Back to index

im-sdk  12.3.91
i18nPtHdr.c
Go to the documentation of this file.
00001 /******************************************************************
00002  
00003          Copyright 1994, 1995 by Sun Microsystems, Inc.
00004          Copyright 1993, 1994 by Hewlett-Packard Company
00005  
00006 Permission to use, copy, modify, distribute, and sell this software
00007 and its documentation for any purpose is hereby granted without fee,
00008 provided that the above copyright notice appear in all copies and
00009 that both that copyright notice and this permission notice appear
00010 in supporting documentation, and that the name of Sun Microsystems, Inc.
00011 and Hewlett-Packard not be used in advertising or publicity pertaining to
00012 distribution of the software without specific, written prior permission.
00013 Sun Microsystems, Inc. and Hewlett-Packard make no representations about
00014 the suitability of this software for any purpose.  It is provided "as is"
00015 without express or implied warranty.
00016  
00017 SUN MICROSYSTEMS INC. AND HEWLETT-PACKARD COMPANY DISCLAIMS ALL
00018 WARRANTIES WITH REGARD TO THIS SOFTWARE, INCLUDING ALL IMPLIED
00019 WARRANTIES OF MERCHANTABILITY AND FITNESS, IN NO EVENT SHALL
00020 SUN MICROSYSTEMS, INC. AND HEWLETT-PACKARD COMPANY BE LIABLE FOR ANY
00021 SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER
00022 RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF
00023 CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR
00024 IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
00025  
00026   Author: Hidetoshi Tajima(tajima@Eng.Sun.COM) Sun Microsystems, Inc.
00027  
00028 ******************************************************************/
00029 #include <sys/param.h>
00030 #include <X11/Xlib.h>
00031 #ifndef NEED_EVENTS
00032 #define NEED_EVENTS
00033 #endif
00034 #include <X11/Xproto.h>
00035 #undef NEED_EVENTS
00036 #include "FrameMgr.h"
00037 #include "X11R6IMProtoData.h"
00038 #include "Xi18n.h"
00039 #include "XIC_Interface.h"
00040 
00041 extern Xi18nClient *_Xi18nFindClient(Xi18n, CARD16);
00042 extern int _Xi18nNeedSwap(Xi18n i18n_core, CARD16 connect_id);
00043 extern void _Xi18nSendMessage(XIMS ims, CARD16 connect_id,
00044                            CARD8 major_opcode, CARD8 minor_opcode,
00045                            unsigned char *data, long length);
00046 extern void _Xi18nSendTriggerKey(XIMS ims, CARD16 connect_id);
00047 extern void _Xi18nChangeIC(XIMS ims, X11R6IMProtocol call_data,
00048                         unsigned char *p, int create_flag);
00049 extern void _Xi18nGetIC(XIMS ims, X11R6IMProtocol call_data, unsigned char *p);
00050 extern void FilterEvent(int icid, XEvent *event);
00051 
00052 void
00053 GetProtocolVersion(CARD16 client_major, CARD16 client_minor,
00054                  CARD16 *server_major, CARD16 *server_minor)
00055 {
00056     *server_major = client_major;
00057     *server_minor = client_minor;
00058 }
00059 
00060 static void
00061 ConnectMessageProc(XIMS ims, X11R6IMProtocol call_data, unsigned char *p) {
00062     Xi18n i18n_core = ims->protocol;
00063     FrameMgr fm;
00064     extern XimFrameRec connect_fr[], connect_reply_fr[];
00065     register int total_size;
00066     CARD16 server_major_version, server_minor_version;
00067     unsigned char *reply = NULL;
00068     IMConnectStruct *imconnect =
00069       (IMConnectStruct*)&call_data->imconnect;
00070     CARD16 connect_id = call_data->any.connect_id;
00071 
00072     /* create FrameMgr */
00073     fm = FrameMgrInit(connect_fr, (char *)p,
00074                     _Xi18nNeedSwap(i18n_core, connect_id));
00075 
00076     /* get data */
00077     FrameMgrGetToken(fm, imconnect->byte_order);
00078     FrameMgrGetToken(fm, imconnect->major_version);
00079     FrameMgrGetToken(fm, imconnect->minor_version);
00080 
00081     /* free FrameMgr */
00082     FrameMgrFree(fm);
00083 
00084     GetProtocolVersion(imconnect->major_version, imconnect->minor_version,
00085                      &server_major_version, &server_minor_version);
00086 #ifdef IM_PROTO_HANDLER
00087     CALL_PROTO_HANDLER;
00088 #else
00089     /* nothing to do here */
00090 #endif
00091 
00092     /* create FrameMgr */
00093     fm = FrameMgrInit(connect_reply_fr, NULL,
00094                     _Xi18nNeedSwap(i18n_core, connect_id));
00095 
00096     total_size = FrameMgrGetTotalSize(fm);
00097     reply = (unsigned char *)malloc(total_size);
00098     if (!reply) {
00099        _Xi18nSendMessage(ims, connect_id, XIM_ERROR, 0, 0, 0);
00100        return;
00101     }
00102     memset(reply, 0, total_size);
00103     FrameMgrSetBuffer(fm, reply);
00104 
00105     FrameMgrPutToken(fm, server_major_version);
00106     FrameMgrPutToken(fm, server_minor_version);
00107 
00108     _Xi18nSendMessage(ims, connect_id, XIM_CONNECT_REPLY,
00109                     0, reply, total_size);
00110 
00111     XFree(reply);
00112     /* free FrameMgr */
00113     FrameMgrFree(fm);
00114     return;
00115 }
00116 
00117 static void
00118 DisConnectMessageProc(XIMS ims, X11R6IMProtocol call_data) {
00119     Xi18n i18n_core = ims->protocol;
00120     unsigned char *reply = NULL;
00121     CARD16 connect_id = call_data->any.connect_id;
00122 
00123 #ifdef IM_PROTO_HANDLER
00124     CALL_PROTO_HANDLER;
00125 #else
00126     /* destroy all remaining input contexts for this connection */
00127 #endif
00128 
00129     _Xi18nSendMessage(ims, connect_id, XIM_DISCONNECT_REPLY,
00130                     0, reply, 0);
00131 
00132     i18n_core->methods.disconnect(ims, connect_id);
00133     return;
00134 }
00135 
00136 static void
00137 OpenMessageProc(XIMS ims, X11R6IMProtocol call_data, unsigned char *p) {
00138     Xi18n i18n_core = ims->protocol;
00139     FrameMgr fm;
00140     extern XimFrameRec open_fr[], open_reply_fr[];
00141     unsigned char *reply = NULL;
00142     int str_size;
00143     register int i, total_size;
00144     CARD16 connect_id = call_data->any.connect_id;
00145     int str_length;
00146     char *name;
00147     IMOpenStruct *imopen =
00148       (IMOpenStruct *)&call_data->imopen;
00149 
00150     /* create FrameMgr */
00151     fm = FrameMgrInit(open_fr, (char *)p,
00152                     _Xi18nNeedSwap(i18n_core, connect_id));
00153 
00154     /* get data */
00155     FrameMgrGetToken(fm, str_length);
00156     FrameMgrSetSize(fm, str_length);
00157     FrameMgrGetToken(fm, name);
00158     imopen->lang.length = str_length;
00159     imopen->lang.name = malloc(str_length + 1);
00160     strncpy(imopen->lang.name, name, str_length);
00161     imopen->lang.name[str_length] = (char)0;
00162 
00163     /* free FrameMgr */
00164     FrameMgrFree(fm);
00165 
00166 #ifdef IM_PROTO_HANDLER
00167     CALL_PROTO_HANDLER;
00168 #else
00169     /* nothing to do here */
00170 #endif
00171 
00172     if ((i18n_core->address.imvalue_mask & I18N_ON_KEYS) ||
00173        (i18n_core->address.imvalue_mask & I18N_OFF_KEYS)) {
00174        _Xi18nSendTriggerKey(ims, connect_id);
00175     }
00176     XFree(imopen->lang.name);
00177 
00178     /* create FrameMgr */
00179     fm = FrameMgrInit(open_reply_fr, NULL,
00180                     _Xi18nNeedSwap(i18n_core, connect_id));
00181 
00182     /* set iteration count for list of imattr */
00183     FrameMgrSetIterCount(fm, i18n_core->address.im_attr_num);
00184 
00185     /* set length of BARRAY item in ximattr_fr */
00186     for (i = 0; i < i18n_core->address.im_attr_num; i++) {
00187        str_size = strlen(i18n_core->address.xim_attr[i].name);
00188        FrameMgrSetSize(fm, str_size);
00189     }
00190     /* set iteration count for list of icattr */
00191     FrameMgrSetIterCount(fm, i18n_core->address.ic_attr_num);
00192     /* set length of BARRAY item in xicattr_fr */
00193     for (i = 0; i < i18n_core->address.ic_attr_num; i++) {
00194        str_size = strlen(i18n_core->address.xic_attr[i].name);
00195        FrameMgrSetSize(fm, str_size);
00196     }
00197 
00198     total_size = FrameMgrGetTotalSize(fm);
00199     reply = (unsigned char *)malloc(total_size);
00200     if (!reply) {
00201        _Xi18nSendMessage(ims, connect_id, XIM_ERROR, 0, 0, 0);
00202        return;
00203     }
00204     memset(reply, 0, total_size);
00205     FrameMgrSetBuffer(fm, reply);
00206 
00207     /* input input-method ID */
00208     FrameMgrPutToken(fm, connect_id);
00209 
00210     for (i = 0; i < i18n_core->address.im_attr_num; i++) {
00211        str_size = FrameMgrGetSize(fm);
00212        FrameMgrPutToken(fm, i18n_core->address.xim_attr[i].attribute_id);
00213        FrameMgrPutToken(fm, i18n_core->address.xim_attr[i].type);
00214        FrameMgrPutToken(fm, str_size);
00215        FrameMgrPutToken(fm, i18n_core->address.xim_attr[i].name);
00216     }
00217     for (i = 0; i < i18n_core->address.ic_attr_num; i++) {
00218        str_size = FrameMgrGetSize(fm);
00219        FrameMgrPutToken(fm, i18n_core->address.xic_attr[i].attribute_id);
00220        FrameMgrPutToken(fm, i18n_core->address.xic_attr[i].type);
00221        FrameMgrPutToken(fm, str_size);
00222        FrameMgrPutToken(fm, i18n_core->address.xic_attr[i].name);
00223     }
00224 
00225     _Xi18nSendMessage(ims, connect_id, XIM_OPEN_REPLY,
00226                     0, reply, total_size);
00227 
00228     XFree(reply);
00229     /* free FrameMgr */
00230     FrameMgrFree(fm);
00231     return;
00232 }
00233 
00234 static void
00235 CloseMessageProc(XIMS ims, X11R6IMProtocol call_data, unsigned char *p) {
00236     Xi18n i18n_core = ims->protocol;
00237     FrameMgr fm;
00238     extern XimFrameRec close_fr[], close_reply_fr[];
00239     unsigned char *reply = NULL;
00240     register int total_size;
00241     CARD16 connect_id = call_data->any.connect_id;
00242     CARD16 input_method_ID;
00243 
00244     /* create FrameMgr */
00245     fm = FrameMgrInit(close_fr, (char *)p,
00246                     _Xi18nNeedSwap(i18n_core, connect_id));
00247 
00248     FrameMgrGetToken(fm, input_method_ID);
00249 
00250     /* free FrameMgr */
00251     FrameMgrFree(fm);
00252 
00253 #ifdef IM_PROTO_HANDLER
00254     CALL_PROTO_HANDLER;
00255 #else
00256     /* nothing to do here */
00257 #endif
00258 
00259     /* create FrameMgr */
00260     fm = FrameMgrInit(close_reply_fr, NULL,
00261                     _Xi18nNeedSwap(i18n_core, connect_id));
00262 
00263     total_size = FrameMgrGetTotalSize(fm);
00264     reply = (unsigned char *)malloc(total_size);
00265     if (!reply) {
00266        _Xi18nSendMessage(ims, connect_id, XIM_ERROR,
00267                        0, 0, 0);
00268        return;
00269     }
00270     memset(reply, 0, total_size);
00271     FrameMgrSetBuffer(fm, reply);
00272 
00273     FrameMgrPutToken(fm, input_method_ID);
00274 
00275     _Xi18nSendMessage(ims, connect_id, XIM_CLOSE_REPLY,
00276                     0, reply, total_size);
00277 
00278     XFree(reply);
00279     /* free FrameMgr */
00280     FrameMgrFree(fm);
00281     return;
00282 }
00283 
00284 static XIMExt *
00285 MakeExtensionList(Xi18n i18n_core, XIMStr *lib_extension,
00286                 int number, int *reply_number) {
00287     XIMExt *ext_list;
00288     XIMExt *im_ext = (XIMExt *)i18n_core->address.extension;
00289     int im_ext_len = i18n_core->address.ext_num;
00290     int i, j;
00291 
00292     *reply_number = 0;
00293 
00294     if (number == 0) {             /* query all extensions */
00295        *reply_number = im_ext_len;
00296     } else {
00297        for (i = 0; i < im_ext_len; i++) {
00298            for (j = 0; j < (int)number; j++) 
00299              if (!strcmp(lib_extension[j].name, im_ext[i].name)) {
00300                 (*reply_number)++;
00301                 break;
00302              }
00303        }
00304     }
00305 
00306     if (!(*reply_number))
00307       return NULL;
00308 
00309     ext_list = (XIMExt *)malloc(sizeof(XIMExt) * (*reply_number));
00310     if (!ext_list)
00311       return NULL;
00312     memset(ext_list, 0, sizeof(XIMExt) * (*reply_number));
00313 
00314     if (number == 0) {             /* query all extensions */
00315        for (i = 0; i < im_ext_len; i++) {
00316            ext_list[i].major_opcode = im_ext[i].major_opcode;
00317            ext_list[i].minor_opcode = im_ext[i].minor_opcode;
00318            ext_list[i].length = im_ext[i].length;
00319            ext_list[i].name = malloc(im_ext[i].length + 1);
00320            strcpy(ext_list[i].name, im_ext[i].name);
00321        }
00322     } else {
00323        int n = 0;
00324        for (i = 0; i < im_ext_len; i++) {
00325            for (j = 0; j < (int)number; j++)
00326              if (!strcmp(lib_extension[j].name, im_ext[i].name)) {
00327                 ext_list[n].major_opcode = im_ext[i].major_opcode;
00328                 ext_list[n].minor_opcode = im_ext[i].minor_opcode;
00329                 ext_list[n].length = im_ext[i].length;
00330                 ext_list[n].name = malloc(im_ext[i].length + 1);
00331                 strcpy(ext_list[n].name, im_ext[i].name);
00332                 n++;
00333                 break;
00334            }
00335        }
00336     }
00337     return ext_list;
00338 }
00339 
00340 static void
00341 QueryExtensionMessageProc(XIMS ims, X11R6IMProtocol call_data,
00342                        unsigned char *p) {
00343     Xi18n i18n_core = ims->protocol;
00344     FrameMgr fm;
00345     FmStatus status;
00346     extern XimFrameRec query_extension_fr[], query_extension_reply_fr[];
00347     unsigned char *reply = NULL;
00348     int str_size;
00349     register int i, number, total_size;
00350     int byte_length;
00351     int reply_number = 0;
00352     XIMExt *ext_list;
00353     CARD16 connect_id = call_data->any.connect_id;
00354     CARD16 input_method_ID;
00355     IMQueryExtensionStruct *query_ext =
00356       (IMQueryExtensionStruct *)&call_data->queryext;
00357     XPointer listofStr = NULL;
00358     XPointer listofStr_p = NULL;
00359 
00360     /* create FrameMgr */
00361     fm = FrameMgrInit(query_extension_fr, (char *)p,
00362                     _Xi18nNeedSwap(i18n_core, connect_id));
00363 
00364     FrameMgrGetToken(fm, input_method_ID);
00365     FrameMgrGetToken(fm, byte_length);
00366     if (byte_length > 0) {
00367        listofStr = (XPointer)malloc(byte_length);
00368        memset(listofStr, 0, byte_length);
00369        listofStr_p = listofStr;
00370     }
00371     number = 0;
00372     while (FrameMgrIsIterLoopEnd(fm, &status) == False) {
00373        char *name;
00374        CARD8 str_length;
00375        FrameMgrGetToken(fm, str_length);
00376        FrameMgrSetSize(fm, str_length);
00377        memmove(listofStr_p++, &str_length, 1);
00378        FrameMgrGetToken(fm, name);
00379        strncpy(listofStr_p, name, str_length);
00380        listofStr_p += str_length;
00381        number++;
00382     }
00383     query_ext->extension = (XIMStr *)malloc(sizeof(XIMStr) * number);
00384     memset(query_ext->extension, 0, sizeof(XIMStr) * number);
00385     query_ext->number = number;
00386     for (listofStr_p = listofStr,i = 0; i < number; i++) {
00387        CARD8 str_length;
00388        str_length = (CARD8)(*listofStr_p++);
00389        query_ext->extension[i].length = str_length;
00390        query_ext->extension[i].name = malloc(str_length + 1);
00391        memmove(query_ext->extension[i].name, listofStr_p, str_length);
00392        query_ext->extension[i].name[str_length] = (char)0;
00393        listofStr_p += str_length;
00394     }
00395 
00396     if (listofStr) XFree(listofStr);
00397 
00398 #ifdef IM_PROTO_HANDLER
00399     CALL_PROTO_HANDLER;
00400 #else
00401     /* nothing to do here  */
00402 #endif
00403 
00404     /* free FrameMgr */
00405     FrameMgrFree(fm);
00406 
00407     ext_list = MakeExtensionList(i18n_core, query_ext->extension, number,
00408                              &reply_number);
00409 
00410     for (i = 0; i < number; i++) {
00411        XFree(query_ext->extension[i].name);
00412     }
00413     XFree(query_ext->extension);
00414 
00415     /* create FrameMgr */
00416     fm = FrameMgrInit(query_extension_reply_fr, NULL,
00417                     _Xi18nNeedSwap(i18n_core, connect_id));
00418 
00419     /* set iteration count for list of extensions */
00420     FrameMgrSetIterCount(fm, reply_number);
00421 
00422     /* set length of BARRAY item in ext_fr */
00423     for (i = 0; i < reply_number; i++) {
00424        str_size = strlen(ext_list[i].name);
00425        FrameMgrSetSize(fm, str_size);
00426     }
00427 
00428     total_size = FrameMgrGetTotalSize(fm);
00429     reply = (unsigned char *)malloc(total_size);
00430     if (!reply) {
00431        _Xi18nSendMessage(ims, connect_id, XIM_ERROR,
00432                        0, 0, 0);
00433        return;
00434     }
00435     memset(reply, 0, total_size);
00436     FrameMgrSetBuffer(fm, reply);
00437 
00438     FrameMgrPutToken(fm, input_method_ID);
00439 
00440     for (i = 0; i < reply_number; i++) {
00441        str_size = FrameMgrGetSize(fm);
00442        FrameMgrPutToken(fm, ext_list[i].major_opcode);
00443        FrameMgrPutToken(fm, ext_list[i].minor_opcode);
00444        FrameMgrPutToken(fm, str_size);
00445        FrameMgrPutToken(fm, ext_list[i].name);
00446     }
00447     _Xi18nSendMessage(ims, connect_id,
00448                     XIM_QUERY_EXTENSION_REPLY, 0, reply, total_size);
00449     XFree(reply);
00450     /* free FrameMgr */
00451     FrameMgrFree(fm);
00452 
00453     for (i = 0; i < reply_number; i++) {
00454        XFree(ext_list[i].name);
00455     }
00456     XFree((char *)ext_list);
00457     return;
00458 }
00459 
00460 static void
00461 SyncReplyMessageProc(XIMS ims, X11R6IMProtocol call_data,
00462                    unsigned char *p) {
00463     Xi18n i18n_core = ims->protocol;
00464     FrameMgr fm;
00465     extern XimFrameRec sync_reply_fr[];
00466     CARD16 connect_id = call_data->any.connect_id;
00467     Xi18nClient *client = (Xi18nClient *)_Xi18nFindClient(i18n_core,
00468                                                    connect_id);
00469     CARD16 input_method_ID, input_context_ID;
00470 
00471     /* create FrameMgr */
00472     fm = FrameMgrInit(sync_reply_fr, (char *)p,
00473                     _Xi18nNeedSwap(i18n_core, connect_id));
00474     FrameMgrGetToken(fm, input_method_ID);
00475     FrameMgrGetToken(fm, input_context_ID);
00476     /* free FrameMgr */
00477     FrameMgrFree(fm);
00478 
00479     client->sync = False;
00480     return;
00481 }
00482 
00483 static void
00484 GetIMValueFromName(Xi18n i18n_core, CARD16 connect_id,
00485                  char *buf, const char *name, int *length) {
00486     register int i;
00487     
00488     if (!strcmp(name, XNQueryInputStyle)) {
00489        XIMStyles *styles = (XIMStyles*)&i18n_core->address.input_styles;
00490 
00491        *length = sizeof(CARD16) * 2;      /* count_styles, unused */
00492        *length += styles->count_styles * sizeof(CARD32);
00493 
00494        if (buf != NULL) {
00495            FrameMgr fm;
00496            extern XimFrameRec ximstyles_fr[];
00497            unsigned char *data = NULL;
00498            int total_size;
00499            /* create FrameMgr */
00500            fm = FrameMgrInit(ximstyles_fr, NULL,
00501                            _Xi18nNeedSwap(i18n_core, connect_id));
00502 
00503            /* set iteration count for list of input_style */
00504            FrameMgrSetIterCount(fm, styles->count_styles);
00505 
00506            total_size = FrameMgrGetTotalSize(fm);
00507            data = (unsigned char *)malloc(total_size);
00508            if (!data) {
00509               return;
00510            }
00511            memset(data, 0, total_size);
00512            FrameMgrSetBuffer(fm, data);
00513 
00514            FrameMgrPutToken(fm, styles->count_styles);
00515            for (i = 0; i < (int)styles->count_styles; i++) {
00516               FrameMgrPutToken(fm, styles->supported_styles[i]);
00517            }
00518            memmove(buf, data, total_size);
00519 
00520            XFree(data);
00521            /* free FrameMgr */
00522            FrameMgrFree(fm);
00523        }
00524     }
00525 }
00526 
00527 static XIMAttribute *
00528 MakeIMAttributeList(Xi18n i18n_core, CARD16 connect_id,
00529                   CARD16 *list, int *number, int *length) {
00530     XIMAttribute *attrib_list;
00531     int list_num;
00532     XIMAttr *attr = i18n_core->address.xim_attr;
00533     int list_len = i18n_core->address.im_attr_num;
00534     register int i, j;
00535     int value_length;
00536     int number_ret = 0;
00537 
00538     *length = 0;
00539     list_num = 0;
00540     for (i = 0; i < *number; i++) {
00541        for (j = 0; j < list_len; j++) {
00542            if (attr[j].attribute_id == list[i]) {
00543               list_num++;
00544               break;
00545            }
00546        }
00547     }
00548     attrib_list = (XIMAttribute *)malloc(sizeof(XIMAttribute) * list_num);
00549     if (!attrib_list)
00550       return NULL;
00551     memset(attrib_list, 0, sizeof(XIMAttribute) * list_num);
00552     number_ret = list_num;
00553     list_num = 0;
00554     for (i = 0; i < *number; i++) {
00555        for (j = 0; j < list_len; j++) {
00556            if (attr[j].attribute_id == list[i]) {
00557               attrib_list[list_num].attribute_id = attr[j].attribute_id;
00558               attrib_list[list_num].name_length = attr[j].length;
00559               attrib_list[list_num].name = attr[j].name;
00560               attrib_list[list_num].type = attr[j].type;
00561               GetIMValueFromName(i18n_core, connect_id,
00562                                NULL,
00563                                attr[j].name, &value_length);
00564               attrib_list[list_num].value_length = value_length;
00565               attrib_list[list_num].value = (void *)malloc(value_length);
00566               memset(attrib_list[list_num].value, 0, value_length);
00567               GetIMValueFromName(i18n_core, connect_id,
00568                                attrib_list[list_num].value,
00569                                attr[j].name, &value_length);
00570               *length += sizeof(CARD16) * 2;
00571               *length += value_length;
00572               *length += IMPAD(value_length);
00573               list_num++;
00574               break;
00575            }
00576        }
00577     }
00578     *number = number_ret;
00579     return attrib_list;
00580 }
00581 
00582 static void
00583 GetIMValuesMessageProc(XIMS ims, X11R6IMProtocol call_data,
00584                      unsigned char *p) {
00585     Xi18n i18n_core = ims->protocol;
00586     FrameMgr fm;
00587     FmStatus status;
00588     extern XimFrameRec get_im_values_fr[], get_im_values_reply_fr[];
00589     CARD16 byte_length;
00590     int list_len, total_size;
00591     unsigned char *reply = NULL;
00592     int iter_count;
00593     register int i, j;
00594     int number;
00595     CARD16 *im_attrID_list;
00596     char **name_list;
00597     CARD16 name_number;
00598     XIMAttribute *im_attribute_list;
00599     IMGetIMValuesStruct *getim =
00600       (IMGetIMValuesStruct *)&call_data->getim;
00601     CARD16 connect_id = call_data->any.connect_id;
00602     CARD16 input_method_ID;
00603 
00604     /* create FrameMgr */
00605     fm = FrameMgrInit(get_im_values_fr, (char *)p,
00606                     _Xi18nNeedSwap(i18n_core, connect_id));
00607 
00608     FrameMgrGetToken(fm, input_method_ID);
00609     FrameMgrGetToken(fm, byte_length);
00610     im_attrID_list = (CARD16 *)malloc(sizeof(CARD16) * 20);
00611     memset(im_attrID_list, 0, sizeof(CARD16) * 20);
00612     name_list = (char **)malloc(sizeof(char *) * 20);
00613     memset(name_list, 0, sizeof(char *) * 20);
00614     number = 0;
00615     while (FrameMgrIsIterLoopEnd(fm, &status) == False) {
00616        FrameMgrGetToken(fm, im_attrID_list[number]);
00617        number++;
00618     }
00619     /* free FrameMgr */
00620     FrameMgrFree(fm);
00621 
00622     name_number = 0;
00623     for (i = 0; i < number; i++) {
00624        for (j = 0; j < i18n_core->address.im_attr_num; j++)
00625          if (i18n_core->address.xim_attr[j].attribute_id == im_attrID_list[i]) {
00626              name_list[name_number++] = (char*)i18n_core->address.xim_attr[j].name;
00627              break;
00628          }
00629     }
00630 
00631     getim->number = name_number;
00632     getim->im_attr_list = name_list;
00633 
00634 #ifdef IM_PROTO_HANDLER
00635     CALL_PROTO_HANDLER;
00636 #endif
00637 
00638     XFree(name_list);
00639 
00640     im_attribute_list = MakeIMAttributeList(i18n_core, connect_id,
00641                                        im_attrID_list,
00642                                        &number, &list_len);
00643     if (im_attrID_list)
00644       XFree(im_attrID_list);
00645 
00646     /* create FrameMgr */
00647     fm = FrameMgrInit(get_im_values_reply_fr, NULL,
00648                     _Xi18nNeedSwap(i18n_core, connect_id));
00649 
00650     iter_count = number;
00651 
00652     /* set iteration count for list of im_attribute */
00653     FrameMgrSetIterCount(fm, iter_count);
00654 
00655     /* set length of BARRAY item in ximattribute_fr */
00656     for (i = 0; i < iter_count; i++) {
00657        FrameMgrSetSize(fm, im_attribute_list[i].value_length);
00658     }
00659 
00660     total_size = FrameMgrGetTotalSize(fm);
00661     reply = (unsigned char *)malloc(total_size);
00662     if (!reply) {
00663        _Xi18nSendMessage(ims, connect_id, XIM_ERROR, 0, 0, 0);
00664        return;
00665     }
00666     memset(reply, 0, total_size);
00667     FrameMgrSetBuffer(fm, reply);
00668 
00669     FrameMgrPutToken(fm, input_method_ID);
00670 
00671     for (i = 0; i < iter_count; i++) {
00672        FrameMgrPutToken(fm, im_attribute_list[i].attribute_id);
00673        FrameMgrPutToken(fm, im_attribute_list[i].value_length);
00674        FrameMgrPutToken(fm, im_attribute_list[i].value);
00675     }
00676     _Xi18nSendMessage(ims, connect_id,
00677                     XIM_GET_IM_VALUES_REPLY, 0, reply, total_size);
00678     XFree(reply);
00679     /* free FrameMgr */
00680     FrameMgrFree(fm);
00681 
00682     for (i = 0; i < iter_count; i++) {
00683        if (im_attribute_list[i].value_length && im_attribute_list[i].value) {
00684            XFree(im_attribute_list[i].value);
00685        }
00686     }
00687     XFree(im_attribute_list);
00688     return;
00689 }
00690 
00691 static void
00692 CreateICMessageProc(XIMS ims, X11R6IMProtocol call_data, unsigned char *p)
00693 {
00694     _Xi18nChangeIC(ims, call_data, p, True);
00695     return;
00696 }
00697 
00698 static void
00699 SetICValuesMessageProc(XIMS ims, X11R6IMProtocol call_data, unsigned char *p)
00700 {
00701     _Xi18nChangeIC(ims, call_data, p, False);
00702     return;
00703 }
00704 
00705 static void
00706 GetICValuesMessageProc(XIMS ims, X11R6IMProtocol call_data, unsigned char *p)
00707 {
00708     _Xi18nGetIC(ims, call_data, p);
00709     return;
00710 }
00711 
00712 static void
00713 SetICFocusMessageProc(XIMS ims, X11R6IMProtocol call_data, unsigned char *p)
00714 {
00715     Xi18n i18n_core = ims->protocol;
00716     FrameMgr fm;
00717     extern XimFrameRec set_ic_focus_fr[];
00718     IMChangeFocusStruct *setfocus =
00719       (IMChangeFocusStruct*)&call_data->changefocus;
00720     CARD16 connect_id = call_data->any.connect_id;
00721     CARD16 input_method_ID;
00722     Xi18nClient *client = (Xi18nClient *)_Xi18nFindClient(i18n_core,
00723                                                    connect_id);
00724 
00725     while (client->pending_commit != NULL) {
00726       unsigned char *reply = client->pending_commit;
00727       int total_size = client->pending_commit_size;
00728       
00729       _Xi18nSendMessage(ims, connect_id,
00730                      XIM_COMMIT, 0, reply, total_size);
00731       XFree(client->pending_commit);
00732       client->pending_commit = NULL;
00733     }
00734 
00735     /* create FrameMgr */
00736     fm = FrameMgrInit(set_ic_focus_fr, (char *)p,
00737                     _Xi18nNeedSwap(i18n_core, connect_id));
00738 
00739     /* get data */
00740     FrameMgrGetToken(fm, input_method_ID);
00741     FrameMgrGetToken(fm, setfocus->icid);
00742 
00743     /* free FrameMgr */
00744     FrameMgrFree(fm);
00745 
00746 #ifdef IM_PROTO_HANDLER
00747     CALL_PROTO_HANDLER;
00748 #else
00749     SetICFocus(setfocus->icid);
00750 #endif
00751 
00752     return;
00753 }
00754 
00755 static void
00756 UnsetICFocusMessageProc(XIMS ims, X11R6IMProtocol call_data, unsigned char *p)
00757 {
00758     Xi18n i18n_core = ims->protocol;
00759     FrameMgr fm;
00760     extern XimFrameRec unset_ic_focus_fr[];
00761     IMChangeFocusStruct *unsetfocus =
00762       (IMChangeFocusStruct*)&call_data->changefocus;
00763     CARD16 connect_id = call_data->any.connect_id;
00764     CARD16 input_method_ID;
00765 
00766     /* create FrameMgr */
00767     fm = FrameMgrInit(unset_ic_focus_fr, (char *)p,
00768                     _Xi18nNeedSwap(i18n_core, connect_id));
00769 
00770     /* get data */
00771     FrameMgrGetToken(fm, input_method_ID);
00772     FrameMgrGetToken(fm, unsetfocus->icid);
00773 
00774     /* free FrameMgr */
00775     FrameMgrFree(fm);
00776 
00777 #ifdef IM_PROTO_HANDLER
00778     CALL_PROTO_HANDLER;
00779 #else
00780     UnsetICFocus(unsetfocus->icid);
00781 #endif
00782 
00783     return;
00784 }
00785 
00786 static void
00787 DestroyICMessageProc(XIMS ims, X11R6IMProtocol call_data, unsigned char *p)
00788 {
00789     Xi18n i18n_core = ims->protocol;
00790     FrameMgr fm;
00791     extern XimFrameRec destroy_ic_fr[], destroy_ic_reply_fr[];
00792     register int total_size;
00793     unsigned char *reply = NULL;
00794     IMDestroyICStruct *destroy =
00795       (IMDestroyICStruct*)&call_data->destroyic;
00796     CARD16 connect_id = call_data->any.connect_id;
00797     CARD16 input_method_ID;
00798 
00799     /* create FrameMgr */
00800     fm = FrameMgrInit(destroy_ic_fr, (char *)p,
00801                     _Xi18nNeedSwap(i18n_core, connect_id));
00802 
00803     /* get data */
00804     FrameMgrGetToken(fm, input_method_ID);
00805     FrameMgrGetToken(fm, destroy->icid);
00806 
00807     /* free FrameMgr */
00808     FrameMgrFree(fm);
00809 
00810 #ifdef IM_PROTO_HANDLER
00811     CALL_PROTO_HANDLER;
00812 #else
00813     DestroyIC(destroy->icid);
00814 #endif
00815 
00816     /* create FrameMgr */
00817     fm = FrameMgrInit(destroy_ic_reply_fr, NULL,
00818                     _Xi18nNeedSwap(i18n_core, connect_id));
00819 
00820     total_size = FrameMgrGetTotalSize(fm);
00821     reply = (unsigned char *)malloc(total_size);
00822     if (!reply) {
00823        _Xi18nSendMessage(ims, connect_id, XIM_ERROR, 0, 0, 0);
00824        return;
00825     }
00826     memset(reply, 0, total_size);
00827     FrameMgrSetBuffer(fm, reply);
00828 
00829     FrameMgrPutToken(fm, input_method_ID);
00830     FrameMgrPutToken(fm, destroy->icid);
00831 
00832     _Xi18nSendMessage(ims, connect_id,
00833                     XIM_DESTROY_IC_REPLY, 0, reply, total_size);
00834     XFree(reply);
00835     /* free FrameMgr */
00836     FrameMgrFree(fm);
00837     return;
00838 }
00839 
00840 static void
00841 ResetICMessageProc(XIMS ims, X11R6IMProtocol call_data, unsigned char *p)
00842 {
00843     Xi18n i18n_core = ims->protocol;
00844     FrameMgr fm;
00845     extern XimFrameRec reset_ic_fr[], reset_ic_reply_fr[];
00846     register int total_size;
00847     unsigned char *reply = NULL;
00848     IMResetICStruct *resetic =
00849       (IMResetICStruct*)&call_data->resetic;
00850     CARD16 connect_id = call_data->any.connect_id;
00851     CARD16 input_method_ID;
00852     char *mb_data = 0;
00853 
00854     /* create FrameMgr */
00855     fm = FrameMgrInit(reset_ic_fr, (char *)p,
00856                     _Xi18nNeedSwap(i18n_core, connect_id));
00857 
00858     /* get data */
00859     FrameMgrGetToken(fm, input_method_ID);
00860     FrameMgrGetToken(fm, resetic->icid);
00861 
00862     /* free FrameMgr */
00863     FrameMgrFree(fm);
00864 
00865 #ifdef IM_PROTO_HANDLER
00866     CALL_PROTO_HANDLER;
00867 #else
00868     mb_data = ResetIC(resetic->icid);
00869     if (mb_data) {
00870       /* mb_data is native encoding, so need to convert to CT */
00871       XTextProperty prop;
00872       XmbTextListToTextProperty(i18n_core->address.dpy, &mb_data,
00873                             1, XCompoundTextStyle, &prop);
00874       resetic->length = (int)prop.nitems;
00875       resetic->commit_string = (char*)prop.value;
00876     } else {
00877       /* call conversion end */
00878       /* get it from the results of commit_string */
00879     }
00880 #endif
00881     
00882     /* create FrameMgr */
00883     fm = FrameMgrInit(reset_ic_reply_fr, NULL,
00884                     _Xi18nNeedSwap(i18n_core, connect_id));
00885 
00886     /* set length of STRING8 */
00887     FrameMgrSetSize(fm, resetic->length);
00888 
00889     total_size = FrameMgrGetTotalSize(fm);
00890     reply = (unsigned char *)malloc(total_size);
00891     if (!reply) {
00892        _Xi18nSendMessage(ims, connect_id, XIM_ERROR, 0, 0, 0);
00893        return;
00894     }
00895     memset(reply, 0, total_size);
00896     FrameMgrSetBuffer(fm, reply);
00897 
00898     FrameMgrPutToken(fm, input_method_ID);
00899     FrameMgrPutToken(fm, resetic->icid);
00900     FrameMgrPutToken(fm, resetic->length);
00901     if (resetic->commit_string && *(resetic->commit_string))
00902       FrameMgrPutToken(fm, resetic->commit_string);
00903 
00904     _Xi18nSendMessage(ims, connect_id,
00905                     XIM_RESET_IC_REPLY, 0, reply, total_size);
00906     /* execute set/unset focus function to redraw status text */
00907     if (IsFocused(resetic->icid)) {
00908       SetICFocus(resetic->icid);
00909     }
00910     else {
00911       UnsetICFocus(resetic->icid);
00912     }
00913     /* free FrameMgr */
00914     FrameMgrFree(fm);
00915     XFree(reply);
00916     return;
00917 }
00918 
00919 static int
00920 WireEventToEvent(Xi18n i18n_core, xEvent *event,
00921                CARD16 serial, XEvent *ev)
00922 {
00923     ev->xany.serial = event->u.u.sequenceNumber & ((unsigned long) 0xffff);
00924     ev->xany.serial |= serial << 16;
00925     ev->xany.send_event = False;
00926     ev->xany.display = i18n_core->address.dpy;
00927     switch (ev->type = event->u.u.type & 0x7f) {
00928       case KeyPress:
00929       case KeyRelease:
00930        ((XKeyEvent *)ev)->keycode = event->u.u.detail;
00931        ((XKeyEvent *)ev)->window = event->u.keyButtonPointer.event;
00932        /* hack */
00933        if (event->u.keyButtonPointer.state > Mod5Mask) {
00934          /* linux client */
00935          ((XKeyEvent *)ev)->state = event->u.keyButtonPointer.state >> 8;
00936        } else {
00937          /* Solaris client */
00938          ((XKeyEvent *)ev)->state = event->u.keyButtonPointer.state;
00939        }
00940        ((XKeyEvent *)ev)->time = event->u.keyButtonPointer.time;
00941        ((XKeyEvent *)ev)->root = event->u.keyButtonPointer.root;
00942        ((XKeyEvent *)ev)->x = event->u.keyButtonPointer.eventX;
00943        ((XKeyEvent *)ev)->y = event->u.keyButtonPointer.eventY;
00944        ((XKeyEvent *)ev)->x_root = 0;
00945        ((XKeyEvent *)ev)->y_root = 0;
00946        return True;
00947       default:
00948        break;
00949     }
00950     return False;
00951 }
00952 
00953 static void
00954 ForwardEventMessageProc(XIMS ims, X11R6IMProtocol call_data, unsigned char *p)
00955 {
00956     Xi18n i18n_core = ims->protocol;
00957     FrameMgr fm;
00958     extern XimFrameRec forward_event_fr[];
00959     xEvent wire_event;
00960     IMForwardEventStruct *forward =
00961       (IMForwardEventStruct*)&call_data->forwardevent;
00962     CARD16 connect_id = call_data->any.connect_id;
00963     CARD16 input_method_ID;
00964 #ifdef FULL_SYNC_MODE
00965     unsigned char *reply = NULL;
00966     extern XimFrameRec sync_reply_fr[];
00967     register int total_size;
00968 #endif
00969 
00970     /* create FrameMgr */
00971     fm = FrameMgrInit(forward_event_fr, (char *)p,
00972                     _Xi18nNeedSwap(i18n_core, connect_id));
00973 
00974     /* get data */
00975     FrameMgrGetToken(fm, input_method_ID);
00976     FrameMgrGetToken(fm, forward->icid);
00977     FrameMgrGetToken(fm, forward->sync_bit);
00978     FrameMgrGetToken(fm, forward->serial_number);
00979     p += sizeof(CARD16) * 4;
00980     memmove(&wire_event, p, sizeof(xEvent));
00981 
00982     /* free FrameMgr */
00983     FrameMgrFree(fm);
00984 
00985     if (WireEventToEvent(i18n_core, &wire_event,
00986                       forward->serial_number, &forward->event) == True) {
00987 #ifdef IM_PROTO_HANDLER
00988       CALL_PROTO_HANDLER;
00989 #else
00990       FilterEvent(forward->icid, &forward->event);
00991 #endif
00992     }
00993 
00994 #ifdef FULL_SYNC_MODE
00995     /* XIM_SYNC_REPLY needs to be sent to IM library */
00996     fm = FrameMgrInit(sync_reply_fr, NULL,
00997                       _Xi18nNeedSwap(i18n_core, connect_id));
00998 
00999     total_size = FrameMgrGetTotalSize(fm);
01000     reply = (unsigned char *)malloc(total_size);
01001     if (!reply) {
01002         _Xi18nSendMessage(ims, connect_id, XIM_ERROR, 0, 0, 0);
01003         return;
01004     }
01005     memset(reply, 0, total_size);
01006     FrameMgrSetBuffer(fm, reply);
01007 
01008     FrameMgrPutToken(fm, input_method_ID);
01009     FrameMgrPutToken(fm, forward->icid);
01010 
01011     _Xi18nSendMessage(ims, connect_id, XIM_SYNC_REPLY, 0,
01012                           reply, total_size);
01013 
01014     FrameMgrFree(fm);
01015     XFree(reply);
01016 #endif
01017     return;
01018 }
01019 
01020 static void
01021 ExtForwardKeyEventMessageProc(XIMS ims, X11R6IMProtocol call_data,
01022                            unsigned char *p)
01023 {
01024     Xi18n i18n_core = ims->protocol;
01025     FrameMgr fm;
01026     extern XimFrameRec ext_forward_keyevent_fr[];
01027     CARD8 type, keycode;
01028     CARD16 state;
01029     CARD32 ev_time, window;
01030     IMForwardEventStruct *forward =
01031       (IMForwardEventStruct*)&call_data->forwardevent;
01032     XEvent *ev = (XEvent *)&forward->event;
01033     CARD16 connect_id = call_data->any.connect_id;
01034     CARD16 input_method_ID;
01035 
01036     /* create FrameMgr */
01037     fm = FrameMgrInit(ext_forward_keyevent_fr, (char *)p,
01038                     _Xi18nNeedSwap(i18n_core, connect_id));
01039     /* get data */
01040     FrameMgrGetToken(fm, input_method_ID);
01041     FrameMgrGetToken(fm, forward->icid);
01042     FrameMgrGetToken(fm, forward->sync_bit);
01043     FrameMgrGetToken(fm, forward->serial_number);
01044     FrameMgrGetToken(fm, type);
01045     FrameMgrGetToken(fm, keycode);
01046     FrameMgrGetToken(fm, state);
01047     FrameMgrGetToken(fm, ev_time);
01048     FrameMgrGetToken(fm, window);
01049 
01050     /* free FrameMgr */
01051     FrameMgrFree(fm);
01052 
01053     if (type != KeyPress) {
01054        _Xi18nSendMessage(ims, connect_id, XIM_ERROR, 0, 0, 0);
01055        return;
01056     }
01057     /* make a faked keypress event */
01058     ev->type = (int)type;
01059     ev->xany.send_event = True;
01060     ev->xany.display = i18n_core->address.dpy;
01061     ev->xany.serial = (unsigned long)forward->serial_number;
01062     ((XKeyEvent *)ev)->keycode = (unsigned int)keycode;
01063     ((XKeyEvent *)ev)->state = (unsigned int)state;
01064     ((XKeyEvent *)ev)->time = (Time)ev_time;
01065     ((XKeyEvent *)ev)->window = (Window)window;
01066     ((XKeyEvent *)ev)->root = DefaultRootWindow(ev->xany.display);
01067     ((XKeyEvent *)ev)->x = 0;
01068     ((XKeyEvent *)ev)->y = 0;
01069     ((XKeyEvent *)ev)->x_root = 0;
01070     ((XKeyEvent *)ev)->y_root = 0;
01071 
01072 #ifdef IM_PROTO_HANDLER
01073     CALL_PROTO_HANDLER;
01074 #else
01075     FilterEvent(forward->icid, ev);
01076 #endif
01077     return;
01078 }
01079 
01080 static void
01081 ExtMoveMessageProc(XIMS ims, X11R6IMProtocol call_data, unsigned char *p)
01082 {
01083     Xi18n i18n_core = ims->protocol;
01084     FrameMgr fm;
01085     extern XimFrameRec ext_move_fr[];
01086     IMMoveStruct *extmove =
01087       (IMMoveStruct*)&call_data->extmove;
01088     CARD16 connect_id = call_data->any.connect_id;
01089     CARD16 input_method_ID;
01090 
01091     /* create FrameMgr */
01092     fm = FrameMgrInit(ext_move_fr, (char *)p,
01093                     _Xi18nNeedSwap(i18n_core, connect_id));
01094 
01095     /* get data */
01096     FrameMgrGetToken(fm, input_method_ID);
01097     FrameMgrGetToken(fm, extmove->icid);
01098     FrameMgrGetToken(fm, extmove->x);
01099     FrameMgrGetToken(fm, extmove->y);
01100 
01101     /* free FrameMgr */
01102     FrameMgrFree(fm);
01103 
01104 #ifdef IM_PROTO_HANDLER
01105     CALL_PROTO_HANDLER;
01106 #else
01107     MoveSpot(extmove->icid, extmove->x, extmove->y);
01108 #endif
01109     return;
01110 }
01111 
01112 static void
01113 ExtensionMessageProc(XIMS ims, X11R6IMProtocol call_data, unsigned char *p)
01114 {
01115     switch (call_data->any.minor_code) {
01116       case XIM_EXT_FORWARD_KEYEVENT:
01117        ExtForwardKeyEventMessageProc(ims, call_data, p);
01118        break;
01119       case XIM_EXT_MOVE:
01120        ExtMoveMessageProc(ims, call_data, p);
01121        break;
01122     }
01123 }
01124 
01125 static void
01126 TriggerNotifyMessageProc(XIMS ims, X11R6IMProtocol call_data,
01127                       unsigned char *p)
01128 {
01129     Xi18n i18n_core = ims->protocol;
01130     FrameMgr fm;
01131     extern XimFrameRec trigger_notify_fr[], trigger_notify_reply_fr[];
01132     register int total_size;
01133     unsigned char *reply = NULL;
01134     IMTriggerNotifyStruct *trigger =
01135       (IMTriggerNotifyStruct *)&call_data->triggernotify;
01136     CARD16 connect_id = call_data->any.connect_id;
01137     CARD16 input_method_ID;
01138     CARD32 flag;
01139 
01140     /* create FrameMgr */
01141     fm = FrameMgrInit(trigger_notify_fr, (char *)p,
01142                     _Xi18nNeedSwap(i18n_core, connect_id));
01143 
01144     /* get data */
01145     FrameMgrGetToken(fm, input_method_ID);
01146     FrameMgrGetToken(fm, trigger->icid);
01147     FrameMgrGetToken(fm, trigger->flag);
01148     FrameMgrGetToken(fm, trigger->key_index);
01149     FrameMgrGetToken(fm, trigger->event_mask);
01150     /*
01151       In order to support Front End Method, this event_mask must be saved
01152       per clients so that it should be restored by an XIM_EXT_SET_EVENT_MASK
01153       call when preediting mode is reset to off.
01154      */
01155 
01156     flag = trigger->flag;
01157 
01158     /* free FrameMgr */
01159     FrameMgrFree(fm);
01160 
01161     /* create FrameMgr */
01162     fm = FrameMgrInit(trigger_notify_reply_fr, NULL,
01163                     _Xi18nNeedSwap(i18n_core, connect_id));
01164 
01165     total_size = FrameMgrGetTotalSize(fm);
01166     reply = (unsigned char *)malloc(total_size);
01167     if (!reply) {
01168        _Xi18nSendMessage(ims, connect_id, XIM_ERROR, 0, 0, 0);
01169        return;
01170     }
01171     memset(reply, 0, total_size);
01172     FrameMgrSetBuffer(fm, reply);
01173 
01174     FrameMgrPutToken(fm, input_method_ID);
01175     FrameMgrPutToken(fm, trigger->icid);
01176 
01177     if (flag == 0) { /* on key */
01178 #ifndef  FIX_APPLIXWARE_TURBOLINUX42
01179        /* Applixware will not forward key event when XIM_TRIGGER_NOTIFY_REPLY
01180           is sent before SET_MASK */
01181        _Xi18nSendMessage(ims, connect_id, XIM_TRIGGER_NOTIFY_REPLY, 0,
01182                        reply, total_size);
01183 #endif
01184        (ims->methods->preeditStart)(ims, call_data);
01185     }
01186 
01187 #ifdef IM_PROTO_HANDLER
01188     CALL_PROTO_HANDLER;
01189 #else
01190     if (flag == 0) {
01191       ConversionStart(trigger->icid);
01192     } else {
01193       ConversionEnd(trigger->icid);
01194     }
01195 #endif
01196     if (flag == 1) { /* off key */
01197         (ims->methods->preeditEnd)(ims, call_data);
01198        _Xi18nSendMessage(ims, connect_id, XIM_TRIGGER_NOTIFY_REPLY, 0,
01199                        reply, total_size);
01200     }
01201 #ifdef  FIX_APPLIXWARE_TURBOLINUX42
01202     if (flag == 0) { /* on key */
01203        _Xi18nSendMessage(ims, connect_id, XIM_TRIGGER_NOTIFY_REPLY, 0,
01204                        reply, total_size);
01205     }
01206 #endif
01207 
01208     /* free FrameMgr */
01209     FrameMgrFree(fm);
01210     XFree(reply);
01211     return;
01212 }
01213 
01214 static INT16
01215 ChooseEncoding(Xi18n i18n_core,
01216               IMEncodingNegotiationStruct *enc_nego)
01217 {
01218     Xi18nAddressRec *address = (Xi18nAddressRec *)&i18n_core->address;
01219     XIMEncodings *p;
01220     int i, j;
01221     int enc_index;
01222 
01223     p = (XIMEncodings*)&address->encoding_list;
01224     for (i = 0; i < (int)p->count_encodings; i++) {
01225        for (j = 0; j < (int)enc_nego->encoding_number; j++) {
01226            if (!strcmp(p->supported_encodings[i],
01227                      enc_nego->encoding[j].name)) {
01228               enc_index = j;
01229               break;
01230            }
01231        }
01232     }
01233     /*
01234       Encoinding Negotiation isn't supported yet in the IMlibrary, so
01235       rather safe and sound to always return XIM_Default_Encoding_IDX(-1).
01236      */
01237     return (INT16)XIM_Default_Encoding_IDX;
01238 }
01239 
01240 static void
01241 EncodingNegotiatonMessageProc(XIMS ims, X11R6IMProtocol call_data,
01242                            unsigned char *p)
01243 {
01244     Xi18n i18n_core = ims->protocol;
01245     FrameMgr fm;
01246     FmStatus status;
01247     CARD16 byte_length;
01248     extern XimFrameRec encoding_negotiation_fr[];
01249     extern XimFrameRec encoding_negotiation_reply_fr[];
01250     register int i, number, total_size;
01251     unsigned char *reply = NULL;
01252     IMEncodingNegotiationStruct *enc_nego =
01253       (IMEncodingNegotiationStruct *)&call_data->encodingnego;
01254     CARD16 connect_id = call_data->any.connect_id;
01255     CARD16 input_method_ID;
01256     XPointer listofStr = NULL;
01257     XPointer listofStr_p;
01258 
01259     fm = FrameMgrInit(encoding_negotiation_fr, (char *)p,
01260                     _Xi18nNeedSwap(i18n_core, connect_id));
01261 
01262     FrameMgrGetToken(fm, input_method_ID);
01263 
01264     /* get ENCODING STR field */
01265     FrameMgrGetToken(fm, byte_length);
01266     if (byte_length > 0) {
01267        listofStr = (XPointer)malloc(byte_length);
01268        memset(listofStr, 0, byte_length);
01269        listofStr_p = listofStr;
01270 
01271        number = 0;
01272        while (FrameMgrIsIterLoopEnd(fm, &status) == False) {
01273            char *name;
01274            CARD8 str_length;
01275            FrameMgrGetToken(fm, str_length);
01276            FrameMgrSetSize(fm, str_length);
01277            memmove(listofStr_p++, &str_length, 1);
01278            FrameMgrGetToken(fm, name);
01279            strncpy(listofStr_p, name, str_length);
01280            listofStr_p += str_length;
01281            number++;
01282        }
01283        enc_nego->encoding_number = number;
01284        if (number > 0) {
01285            enc_nego->encoding = (XIMStr *)malloc(sizeof(XIMStr) * number);
01286            memset(enc_nego->encoding, 0, sizeof(XIMStr) * number);
01287 
01288            for (listofStr_p = listofStr,i = 0; i < number; i++) {
01289               CARD8 str_length;
01290               str_length = (CARD8)(*listofStr_p++);
01291               enc_nego->encoding[i].length = str_length;
01292               enc_nego->encoding[i].name = malloc(str_length + 1);
01293               memmove(enc_nego->encoding[i].name, listofStr_p, str_length);
01294               enc_nego->encoding[i].name[str_length] = (char)0;
01295               listofStr_p += str_length;
01296            }
01297        }
01298        XFree(listofStr);
01299     }
01300     /* get ENCODING INFO field */
01301     FrameMgrGetToken(fm, byte_length);
01302     if (byte_length > 0) {
01303        listofStr = (XPointer)malloc(byte_length);
01304        memset(listofStr, 0, byte_length);
01305        listofStr_p = listofStr;
01306 
01307        number = 0;
01308        while (FrameMgrIsIterLoopEnd(fm, &status) == False) {
01309            char *name;
01310            CARD8 str_length;
01311            FrameMgrGetToken(fm, str_length);
01312            FrameMgrSetSize(fm, str_length);
01313            memmove(listofStr_p++, &str_length, 1);
01314            FrameMgrGetToken(fm, name);
01315            strncpy(listofStr_p, name, str_length);
01316            listofStr_p += str_length;
01317            number++;
01318        }
01319        enc_nego->encoding_info_number = number;
01320        if (number > 0) {
01321            enc_nego->encodinginfo = (XIMStr *)
01322               malloc(sizeof(XIMStr) * number);
01323            memset(enc_nego->encoding, 0, sizeof(XIMStr) * number);
01324 
01325            for (listofStr_p = listofStr, i = 0; i < number; i++) {
01326               CARD8 str_length;
01327               str_length = (CARD8)(*listofStr_p++);
01328               enc_nego->encodinginfo[i].length = str_length;
01329               enc_nego->encodinginfo[i].name = malloc(str_length + 1);
01330               memmove(enc_nego->encodinginfo[i].name,
01331                      listofStr_p, str_length);
01332               enc_nego->encodinginfo[i].name[str_length] = (char)0;
01333               listofStr_p += str_length;
01334            }
01335        }
01336     }
01337 
01338     enc_nego->enc_index = ChooseEncoding(i18n_core, enc_nego);
01339     enc_nego->category = 0;
01340 
01341 #ifdef IM_PROTO_HANDLER
01342     CALL_PROTO_HANDLER;
01343 #else
01344     /* nothing to do here */
01345 #endif
01346 
01347     /* free FrameMgr */
01348     FrameMgrFree(fm);
01349 
01350     /* create FrameMgr */
01351     fm = FrameMgrInit(encoding_negotiation_reply_fr, NULL,
01352                     _Xi18nNeedSwap(i18n_core, connect_id));
01353 
01354     total_size = FrameMgrGetTotalSize(fm);
01355     reply = (unsigned char *)malloc(total_size);
01356     if (!reply) {
01357        _Xi18nSendMessage(ims, connect_id, XIM_ERROR, 0, 0, 0);
01358        return;
01359     }
01360     memset(reply, 0, total_size);
01361     FrameMgrSetBuffer(fm, reply);
01362 
01363     FrameMgrPutToken(fm, input_method_ID);
01364     FrameMgrPutToken(fm, enc_nego->category);
01365     FrameMgrPutToken(fm, enc_nego->enc_index);
01366 
01367     _Xi18nSendMessage(ims, connect_id,
01368                     XIM_ENCODING_NEGOTIATION_REPLY, 0, reply, total_size);
01369     XFree(reply);
01370 
01371     /* free data for encoding list */
01372     if (enc_nego->encoding != NULL) {
01373        for (i = 0; i < (int)enc_nego->encoding_number; i++) {
01374            XFree(enc_nego->encoding[i].name);
01375        }
01376        XFree(enc_nego->encoding);
01377     }
01378     if (enc_nego->encodinginfo != NULL) {
01379        for (i = 0; i < (int)enc_nego->encoding_info_number; i++) {
01380            XFree(enc_nego->encodinginfo[i].name);
01381        }
01382        XFree(enc_nego->encodinginfo);
01383     }
01384     /* free FrameMgr */
01385     FrameMgrFree(fm);
01386     return;
01387 }
01388 
01389 void
01390 PreeditStartReplyMessageProc(XIMS ims, X11R6IMProtocol call_data,
01391                           unsigned char *p)
01392 {
01393     Xi18n i18n_core = ims->protocol;
01394     FrameMgr fm;
01395     extern XimFrameRec preedit_start_reply_fr[];
01396     IMPreeditCBStruct *preedit_CB =
01397       (IMPreeditCBStruct*)&call_data->preedit_callback;
01398     CARD16 connect_id = call_data->any.connect_id;
01399     CARD16 input_method_ID;
01400 
01401     /* create FrameMgr */
01402     fm = FrameMgrInit(preedit_start_reply_fr, (char *)p,
01403                     _Xi18nNeedSwap(i18n_core, connect_id));
01404     /* get data */
01405     FrameMgrGetToken(fm, input_method_ID);
01406     FrameMgrGetToken(fm, preedit_CB->icid);
01407     FrameMgrGetToken(fm, preedit_CB->todo.return_value);
01408 
01409     /* free FrameMgr */
01410     FrameMgrFree(fm);
01411 
01412 #ifdef IM_PROTO_HANDLER
01413     CALL_PROTO_HANDLER;
01414 #endif
01415 
01416     return;
01417 }
01418 
01419 void
01420 PreeditCaretReplyMessageProc(XIMS ims, X11R6IMProtocol call_data,
01421                           unsigned char *p)
01422 {
01423     Xi18n i18n_core = ims->protocol;
01424     FrameMgr fm;
01425     extern XimFrameRec preedit_caret_reply_fr[];
01426     IMPreeditCBStruct *preedit_CB =
01427       (IMPreeditCBStruct*)&call_data->preedit_callback;
01428     XIMPreeditCaretCallbackStruct *caret =
01429       (XIMPreeditCaretCallbackStruct *)&preedit_CB->todo.caret;
01430     CARD16 connect_id = call_data->any.connect_id;
01431     CARD16 input_method_ID;
01432 
01433     /* create FrameMgr */
01434     fm = FrameMgrInit(preedit_caret_reply_fr, (char *)p,
01435                     _Xi18nNeedSwap(i18n_core, connect_id));
01436     /* get data */
01437     FrameMgrGetToken(fm, input_method_ID);
01438     FrameMgrGetToken(fm, preedit_CB->icid);
01439     FrameMgrGetToken(fm, caret->position);
01440 
01441     /* free FrameMgr */
01442     FrameMgrFree(fm);
01443 
01444 #ifdef IM_PROTO_HANDLER
01445     CALL_PROTO_HANDLER;
01446 #endif
01447 
01448     return;
01449 }
01450 
01451 void
01452 StrConvReplyMessageProc(XIMS ims, X11R6IMProtocol call_data,
01453                      unsigned char *p)
01454 {
01455     return;
01456 }
01457 
01458 static void
01459 AddQueue(Xi18nClient *client, unsigned char *p) {
01460     XIMPending        *new_pend, *last;
01461 
01462     if ((new_pend = (XIMPending *)malloc(sizeof(XIMPending))) == NULL)
01463       return;
01464     new_pend->p = p;
01465     new_pend->next = (XIMPending *)NULL;
01466     if (!client->pending)
01467       client->pending = new_pend;
01468     else {
01469        for (last = client->pending; last->next; last = last->next);
01470        last->next = new_pend;
01471     }
01472     return;
01473 }
01474 
01475 static void
01476 ProcessQueue(XIMS ims, CARD16 connect_id) {
01477     Xi18n i18n_core = ims->protocol;
01478     Xi18nClient *client = (Xi18nClient *)_Xi18nFindClient(i18n_core,
01479                                                    connect_id);
01480 
01481     while (client->sync == False && client->pending != NULL) {
01482        XimProtoHdr *hdr = (XimProtoHdr *)client->pending->p;
01483        unsigned char *p1 = (unsigned char *)(hdr + 1);
01484        X11R6IMProtocolStruct call_data;
01485 
01486        call_data.major_code = hdr->major_opcode;
01487        call_data.any.minor_code = hdr->minor_opcode;
01488        call_data.any.connect_id = connect_id;
01489 
01490        switch (hdr->major_opcode) {
01491          case XIM_FORWARD_EVENT:
01492            ForwardEventMessageProc(ims, &call_data, p1);
01493            break;
01494          default:
01495            break;
01496        }
01497        XFree(hdr);
01498        {
01499            XIMPending *old = client->pending;
01500            client->pending = old->next;
01501            XFree(old);
01502        }
01503     }
01504     return;
01505 }
01506 
01507 void
01508 _Xi18nMessageHandler(XIMS ims, CARD16 connect_id,
01509                    unsigned char *p, Bool *delete) {
01510     XimProtoHdr      *hdr = (XimProtoHdr *)p;
01511     unsigned char *p1 = (unsigned char *)(hdr + 1);
01512     X11R6IMProtocolStruct call_data;
01513     Xi18n i18n_core = ims->protocol;
01514     Xi18nClient *client = (Xi18nClient *)_Xi18nFindClient(i18n_core,
01515                                                    connect_id);
01516 
01517     if (hdr == (XimProtoHdr*)NULL) return;
01518 
01519     memset(&call_data, 0, sizeof(X11R6IMProtocolStruct));
01520 
01521     call_data.major_code = hdr->major_opcode;
01522     call_data.any.minor_code = hdr->minor_opcode;
01523     call_data.any.connect_id = connect_id;
01524 
01525     switch (call_data.major_code) {
01526       case XIM_CONNECT:
01527        ConnectMessageProc(ims, &call_data, p1);
01528        break;
01529       case XIM_DISCONNECT:
01530        DisConnectMessageProc(ims, &call_data);
01531        break;
01532       case XIM_OPEN:
01533        OpenMessageProc(ims, &call_data, p1);
01534        break;
01535       case XIM_CLOSE:
01536        CloseMessageProc(ims, &call_data, p1);
01537        break;
01538       case XIM_QUERY_EXTENSION:
01539        QueryExtensionMessageProc(ims, &call_data, p1);
01540        break;
01541       case XIM_GET_IM_VALUES:
01542        GetIMValuesMessageProc(ims, &call_data, p1);
01543        break;
01544       case XIM_CREATE_IC:
01545        CreateICMessageProc(ims, &call_data, p1);
01546        break;
01547       case XIM_SET_IC_VALUES:
01548        SetICValuesMessageProc(ims, &call_data, p1);
01549        break;
01550       case XIM_GET_IC_VALUES:
01551        GetICValuesMessageProc(ims, &call_data, p1);
01552        break;
01553       case XIM_SET_IC_FOCUS:
01554        SetICFocusMessageProc(ims, &call_data, p1);
01555        break;
01556       case XIM_UNSET_IC_FOCUS:
01557        UnsetICFocusMessageProc(ims, &call_data, p1);
01558        break;
01559       case XIM_DESTROY_IC:
01560        DestroyICMessageProc(ims, &call_data, p1);
01561        break;
01562       case XIM_RESET_IC:
01563        ResetICMessageProc(ims, &call_data, p1);
01564        break;
01565       case XIM_FORWARD_EVENT:
01566        if (client->sync == True) {
01567            AddQueue(client, p);
01568            *delete = False;
01569        } else {
01570            ForwardEventMessageProc(ims, &call_data, p1);
01571        }
01572        break;
01573       case XIM_EXTENSION:
01574        ExtensionMessageProc(ims, &call_data, p1);
01575        break;
01576       case XIM_SYNC:
01577        break;
01578       case XIM_SYNC_REPLY:
01579        SyncReplyMessageProc(ims, &call_data, p1);
01580        ProcessQueue(ims, connect_id);
01581        break;
01582       case XIM_TRIGGER_NOTIFY:
01583        TriggerNotifyMessageProc(ims, &call_data, p1);
01584        break;
01585       case XIM_ENCODING_NEGOTIATION:
01586        EncodingNegotiatonMessageProc(ims, &call_data, p1);
01587        break;
01588       case XIM_PREEDIT_START_REPLY:
01589        PreeditStartReplyMessageProc(ims, &call_data, p1);
01590        break;
01591       case XIM_PREEDIT_CARET_REPLY:
01592        PreeditCaretReplyMessageProc(ims, &call_data, p1);
01593        break;
01594       case XIM_STR_CONVERSION_REPLY:
01595        StrConvReplyMessageProc(ims, &call_data, p1);
01596        break;
01597       default:
01598        break;
01599     }
01600 }