Back to index

im-sdk  12.3.91
i18nClbk.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 <X11/Xlib.h>
00030 #include "X11R6IMProtoData.h"
00031 #include "Xi18n.h"
00032 #include "FrameMgr.h"
00033 
00034 extern int _Xi18nNeedSwap(Xi18n i18n_core, CARD16 connect_id);
00035 extern void _Xi18nSendMessage(XIMS ims, CARD16 connect_id,
00036                            CARD8 major_opcode, CARD8 minor_opcode,
00037                            unsigned char *data, long length);
00038 
00039 int
00040 _Xi18nGeometryCallback(XIMS ims, X11R6IMProtocol call_data)
00041 {
00042     Xi18n i18n_core = ims->protocol;
00043     FrameMgr fm;
00044     extern XimFrameRec geometry_fr[];
00045     int total_size;
00046     unsigned char *reply = NULL;
00047     IMGeometryCBStruct *geometry_CB =
00048       (IMGeometryCBStruct*)&call_data->geometry_callback;
00049     CARD16 connect_id = call_data->any.connect_id;
00050 
00051     /* create FrameMgr */
00052     fm = FrameMgrInit(geometry_fr, NULL,
00053                     _Xi18nNeedSwap(i18n_core, connect_id));
00054 
00055     total_size = FrameMgrGetTotalSize(fm);
00056     reply = (unsigned char *)malloc(total_size);
00057     if (!reply) {
00058        _Xi18nSendMessage(ims, connect_id, XIM_ERROR, 0, 0, 0);
00059        return False;
00060     }
00061     memset(reply, 0, total_size);
00062     FrameMgrSetBuffer(fm, reply);
00063 
00064     FrameMgrPutToken(fm, connect_id);
00065     FrameMgrPutToken(fm, geometry_CB->icid);
00066 
00067     _Xi18nSendMessage(ims, connect_id,
00068                     XIM_GEOMETRY, 0, reply, total_size);
00069     /* free FrameMgr */
00070     FrameMgrFree(fm);
00071     XFree(reply);
00072 
00073     /* XIM_GEOMETRY is an asyncronous protocol,
00074        so return immediately. */
00075     return True;
00076 }
00077 
00078 int
00079 _Xi18nPreeditStartCallback(XIMS ims, X11R6IMProtocol call_data)
00080 {
00081     Xi18n i18n_core = ims->protocol;
00082     FrameMgr fm;
00083     extern XimFrameRec preedit_start_fr[];
00084     int total_size;
00085     unsigned char *reply = NULL;
00086     IMPreeditCBStruct *preedit_CB =
00087       (IMPreeditCBStruct*)&call_data->preedit_callback;
00088     CARD16 connect_id = call_data->any.connect_id;
00089 
00090     /* create FrameMgr */
00091     fm = FrameMgrInit(preedit_start_fr, NULL,
00092                     _Xi18nNeedSwap(i18n_core, connect_id));
00093     total_size = FrameMgrGetTotalSize(fm);
00094     reply = (unsigned char *)malloc(total_size);
00095     if (!reply) {
00096        _Xi18nSendMessage(ims, connect_id, XIM_ERROR, 0, 0, 0);
00097        return False;
00098     }
00099     memset(reply, 0, total_size);
00100     FrameMgrSetBuffer(fm, reply);
00101 
00102     FrameMgrPutToken(fm, connect_id);
00103     FrameMgrPutToken(fm, preedit_CB->icid);
00104 
00105     _Xi18nSendMessage(ims, connect_id,
00106                     XIM_PREEDIT_START, 0, reply, total_size);
00107     /* free FrameMgr */
00108     FrameMgrFree(fm);
00109     XFree(reply);
00110 
00111     return True;
00112 }
00113 
00114 int
00115 _Xi18nPreeditDrawCallback(XIMS ims, X11R6IMProtocol call_data)
00116 {
00117     Xi18n i18n_core = ims->protocol;
00118     FrameMgr fm;
00119     extern XimFrameRec preedit_draw_fr[];
00120     int total_size;
00121     unsigned char *reply = NULL;
00122     IMPreeditCBStruct *preedit_CB =
00123       (IMPreeditCBStruct*)&call_data->preedit_callback;
00124     XIMPreeditDrawCallbackStruct *draw =
00125       (XIMPreeditDrawCallbackStruct *)&preedit_CB->todo.draw;
00126     CARD16 connect_id = call_data->any.connect_id;
00127     int feedback_count, i;
00128     BITMASK32 status = 0x0;
00129     CARD16 str_length;
00130 
00131     if (draw->text == 0 || draw->text->length == 0) {
00132       status = 0x00000001;  /* no text */
00133       feedback_count = 0;
00134     } else if (draw->text->feedback[0] == 0) {
00135       status = 0x00000002;  /* no feedback */
00136       feedback_count = 0;
00137     } else {
00138       /* set iteration count for list of feedback */
00139       for (i = 0;
00140           i < draw->text->length && draw->text->feedback[i] != 0;
00141           i++)
00142        ;
00143       feedback_count = i;
00144     }
00145     /* create FrameMgr */
00146     fm = FrameMgrInit(preedit_draw_fr, NULL,
00147                     _Xi18nNeedSwap(i18n_core, connect_id));
00148 
00149     /* set length of preedit string */
00150     if (draw->text) {
00151       str_length = strlen(draw->text->string.multi_byte);
00152     } else {
00153       str_length = 0;
00154     }
00155     FrameMgrSetSize(fm, str_length);
00156 
00157     FrameMgrSetIterCount(fm, feedback_count);
00158 
00159     total_size = FrameMgrGetTotalSize(fm);
00160     reply = (unsigned char *)malloc(total_size);
00161     if (!reply) {
00162        _Xi18nSendMessage(ims, connect_id, XIM_ERROR, 0, 0, 0);
00163        return False;
00164     }
00165     memset(reply, 0, total_size);
00166     FrameMgrSetBuffer(fm, reply);
00167 
00168     FrameMgrPutToken(fm, connect_id);
00169     FrameMgrPutToken(fm, preedit_CB->icid);
00170     FrameMgrPutToken(fm, draw->caret);
00171     FrameMgrPutToken(fm, draw->chg_first);
00172     FrameMgrPutToken(fm, draw->chg_length);
00173     FrameMgrPutToken(fm, status);
00174     FrameMgrPutToken(fm, str_length);
00175     if (draw->text) {
00176       FrameMgrPutToken(fm, draw->text->string.multi_byte);
00177       for (i = 0; i < feedback_count; i++) {
00178        FrameMgrPutToken(fm, draw->text->feedback[i]);
00179       }
00180     }
00181     _Xi18nSendMessage(ims, connect_id,
00182                     XIM_PREEDIT_DRAW, 0, reply, total_size);
00183     /* free FrameMgr */
00184     FrameMgrFree(fm);
00185     XFree(reply);
00186 
00187     /* XIM_PREEDIT_DRAW is an asyncronous protocol,
00188        so return immediately. */
00189     return True;
00190 }
00191 
00192 int
00193 _Xi18nPreeditCaretCallback(XIMS ims, X11R6IMProtocol call_data)
00194 {
00195     Xi18n i18n_core = ims->protocol;
00196     FrameMgr fm;
00197     extern XimFrameRec preedit_caret_fr[];
00198     int total_size;
00199     unsigned char *reply = NULL;
00200     IMPreeditCBStruct *preedit_CB =
00201       (IMPreeditCBStruct*)&call_data->preedit_callback;
00202     XIMPreeditCaretCallbackStruct *caret =
00203       (XIMPreeditCaretCallbackStruct *)&preedit_CB->todo.caret;
00204     CARD16 connect_id = call_data->any.connect_id;
00205 
00206     /* create FrameMgr */
00207     fm = FrameMgrInit(preedit_caret_fr, NULL,
00208                     _Xi18nNeedSwap(i18n_core, connect_id));
00209 
00210     total_size = FrameMgrGetTotalSize(fm);
00211     reply = (unsigned char *)malloc(total_size);
00212     if (!reply) {
00213        _Xi18nSendMessage(ims, connect_id, XIM_ERROR, 0, 0, 0);
00214        return False;
00215     }
00216     memset(reply, 0, total_size);
00217     FrameMgrSetBuffer(fm, reply);
00218 
00219     FrameMgrPutToken(fm, connect_id);
00220     FrameMgrPutToken(fm, preedit_CB->icid);
00221     FrameMgrPutToken(fm, caret->position);
00222     FrameMgrPutToken(fm, caret->direction);
00223     FrameMgrPutToken(fm, caret->style);
00224 
00225     _Xi18nSendMessage(ims, connect_id,
00226                     XIM_PREEDIT_CARET, 0, reply, total_size);
00227     /* free FrameMgr */
00228     FrameMgrFree(fm);
00229     XFree(reply);
00230 
00231     return True;
00232 }
00233 
00234 int
00235 _Xi18nPreeditDoneCallback(XIMS ims, X11R6IMProtocol call_data)
00236 {
00237     Xi18n i18n_core = ims->protocol;
00238     FrameMgr fm;
00239     extern XimFrameRec preedit_done_fr[];
00240     int total_size;
00241     unsigned char *reply = NULL;
00242     IMPreeditCBStruct *preedit_CB =
00243       (IMPreeditCBStruct*)&call_data->preedit_callback;
00244     CARD16 connect_id = call_data->any.connect_id;
00245 
00246     /* create FrameMgr */
00247     fm = FrameMgrInit(preedit_done_fr, NULL,
00248                     _Xi18nNeedSwap(i18n_core, connect_id));
00249 
00250     total_size = FrameMgrGetTotalSize(fm);
00251     reply = (unsigned char *)malloc(total_size);
00252     if (!reply) {
00253        _Xi18nSendMessage(ims, connect_id, XIM_ERROR, 0, 0, 0);
00254        return False;
00255     }
00256     memset(reply, 0, total_size);
00257     FrameMgrSetBuffer(fm, reply);
00258 
00259     FrameMgrPutToken(fm, connect_id);
00260     FrameMgrPutToken(fm, preedit_CB->icid);
00261 
00262     _Xi18nSendMessage(ims, connect_id,
00263                     XIM_PREEDIT_DONE, 0, reply, total_size);
00264     /* free FrameMgr */
00265     FrameMgrFree(fm);
00266     XFree(reply);
00267 
00268     /* XIM_PREEDIT_DONE is an asyncronous protocol,
00269        so return immediately. */
00270     return True;
00271 }
00272 
00273 int
00274 _Xi18nStatusStartCallback(XIMS ims, X11R6IMProtocol call_data)
00275 {
00276     Xi18n i18n_core = ims->protocol;
00277     FrameMgr fm;
00278     extern XimFrameRec status_start_fr[];
00279     int total_size;
00280     unsigned char *reply = NULL;
00281     IMStatusCBStruct *status_CB =
00282       (IMStatusCBStruct*)&call_data->status_callback;
00283     CARD16 connect_id = call_data->any.connect_id;
00284 
00285 #ifdef  FIX_APPLIXWARE_TURBOLINUX42
00286        if(getenv("HTT_DISABLE_STATUS_CALLBACK")){
00287               return True;
00288        }
00289 #endif
00290 
00291     /* create FrameMgr */
00292     fm = FrameMgrInit(status_start_fr, NULL,
00293                     _Xi18nNeedSwap(i18n_core, connect_id));
00294     total_size = FrameMgrGetTotalSize(fm);
00295     reply = (unsigned char *)malloc(total_size);
00296     if (!reply) {
00297        _Xi18nSendMessage(ims, connect_id, XIM_ERROR, 0, 0, 0);
00298        return False;
00299     }
00300     memset(reply, 0, total_size);
00301     FrameMgrSetBuffer(fm, reply);
00302 
00303     FrameMgrPutToken(fm, connect_id);
00304     FrameMgrPutToken(fm, status_CB->icid);
00305 
00306     _Xi18nSendMessage(ims, connect_id,
00307                     XIM_STATUS_START, 0, reply, total_size);
00308     /* free FrameMgr */
00309     FrameMgrFree(fm);
00310     XFree(reply);
00311 
00312     /* XIM_STATUS_START is an asyncronous protocol,
00313        so return immediately. */
00314     return True;
00315 }
00316 
00317 int
00318 _Xi18nStatusDrawCallback(XIMS ims, X11R6IMProtocol call_data)
00319 {
00320     Xi18n i18n_core = ims->protocol;
00321     FrameMgr fm = NULL;
00322     extern XimFrameRec status_draw_text_fr[], status_draw_bitmap_fr[];
00323     int total_size = 0;
00324     unsigned char *reply = NULL;
00325     IMStatusCBStruct *status_CB =
00326       (IMStatusCBStruct*)&call_data->status_callback;
00327     XIMStatusDrawCallbackStruct *draw =
00328       (XIMStatusDrawCallbackStruct *)&status_CB->todo.draw;
00329     CARD16 connect_id = call_data->any.connect_id;
00330     int feedback_count, i;
00331     BITMASK32 status = 0x0;
00332     CARD16 str_length;
00333 
00334 #ifdef  FIX_APPLIXWARE_TURBOLINUX42
00335        if(getenv("HTT_DISABLE_STATUS_CALLBACK")){
00336               return True;
00337        }
00338 #endif
00339 
00340     switch (draw->type) {
00341       case XIMTextType:
00342        /* create FrameMgr */
00343        fm = FrameMgrInit(status_draw_text_fr, NULL,
00344                        _Xi18nNeedSwap(i18n_core, connect_id));
00345 
00346        if (draw->data.text == 0 || draw->data.text->length == 0) {
00347          status = 0x00000001;      /* no text */
00348          feedback_count = 0;
00349        } else if (draw->data.text->feedback[0] == 0) {
00350          status = 0x00000002;      /* no feedback */
00351          feedback_count = 0;
00352        } else {
00353          /* set iteration count for list of feedback */
00354          for (i = 0;
00355               i < draw->data.text->length && draw->data.text->feedback[i] != 0;
00356               i++)
00357            ;
00358          feedback_count = i;
00359        }
00360 
00361        /* set length of status string */
00362        if (draw->data.text) {
00363          str_length = strlen(draw->data.text->string.multi_byte);
00364        } else {
00365          str_length = 0;
00366        }
00367        FrameMgrSetSize(fm, str_length);
00368 
00369        FrameMgrSetIterCount(fm, feedback_count);
00370 
00371        total_size = FrameMgrGetTotalSize(fm);
00372        reply = (unsigned char *)malloc(total_size);
00373        if (!reply) {
00374            _Xi18nSendMessage(ims, connect_id, XIM_ERROR, 0, 0, 0);
00375            return False;
00376        }
00377        memset(reply, 0, total_size);
00378        FrameMgrSetBuffer(fm, reply);
00379 
00380        FrameMgrPutToken(fm, connect_id);
00381        FrameMgrPutToken(fm, status_CB->icid);
00382        FrameMgrPutToken(fm, draw->type);
00383        FrameMgrPutToken(fm, status);
00384        FrameMgrPutToken(fm, str_length);
00385        if (draw->data.text) {
00386          FrameMgrPutToken(fm, draw->data.text->string.multi_byte);
00387          for (i = 0; i < feedback_count; i++) {
00388            FrameMgrPutToken(fm, draw->data.text->feedback[i]);
00389          }
00390        }
00391        break;
00392       case XIMBitmapType:
00393        /* create FrameMgr */
00394        fm = FrameMgrInit(status_draw_bitmap_fr, NULL,
00395                        _Xi18nNeedSwap(i18n_core, connect_id));
00396 
00397        total_size = FrameMgrGetTotalSize(fm);
00398        reply = (unsigned char *)malloc(total_size);
00399        if (!reply) {
00400            _Xi18nSendMessage(ims, connect_id, XIM_ERROR, 0, 0, 0);
00401            return False;
00402        }
00403        memset(reply, 0, total_size);
00404        FrameMgrSetBuffer(fm, reply);
00405 
00406        FrameMgrPutToken(fm, connect_id);
00407        FrameMgrPutToken(fm, status_CB->icid);
00408        FrameMgrPutToken(fm, draw->data.bitmap);
00409        break;
00410     }
00411     _Xi18nSendMessage(ims, connect_id,
00412                     XIM_STATUS_DRAW, 0, reply, total_size);
00413     /* free FrameMgr */
00414     FrameMgrFree(fm);
00415     XFree(reply);
00416 
00417     /* XIM_STATUS_DRAW is an asyncronous protocol,
00418        so return immediately. */
00419     return True;
00420 }
00421 
00422 int
00423 _Xi18nStatusDoneCallback(XIMS ims, X11R6IMProtocol call_data)
00424 {
00425     Xi18n i18n_core = ims->protocol;
00426     FrameMgr fm;
00427     extern XimFrameRec status_done_fr[];
00428     int total_size;
00429     unsigned char *reply = NULL;
00430     IMStatusCBStruct *status_CB =
00431       (IMStatusCBStruct*)&call_data->status_callback;
00432     CARD16 connect_id = call_data->any.connect_id;
00433 
00434 #ifdef  FIX_APPLIXWARE_TURBOLINUX42
00435        if(getenv("HTT_DISABLE_STATUS_CALLBACK")){
00436               return True;
00437        }
00438 #endif
00439 
00440     /* create FrameMgr */
00441     fm = FrameMgrInit(status_done_fr, NULL,
00442                     _Xi18nNeedSwap(i18n_core, connect_id));
00443 
00444     total_size = FrameMgrGetTotalSize(fm);
00445     reply = (unsigned char *)malloc(total_size);
00446     if (!reply) {
00447        _Xi18nSendMessage(ims, connect_id, XIM_ERROR, 0, 0, 0);
00448        return False;
00449     }
00450     memset(reply, 0, total_size);
00451     FrameMgrSetBuffer(fm, reply);
00452 
00453     FrameMgrPutToken(fm, connect_id);
00454     FrameMgrPutToken(fm, status_CB->icid);
00455 
00456     _Xi18nSendMessage(ims, connect_id,
00457                     XIM_STATUS_DONE, 0, reply, total_size);
00458     /* free FrameMgr */
00459     FrameMgrFree(fm);
00460     XFree(reply);
00461 
00462     /* XIM_STATUS_DONE is an asyncronous protocol,
00463        so return immediately. */
00464     return True;
00465 }
00466 
00467 int
00468 _Xi18nStringConversionCallback(XIMS ims, X11R6IMProtocol call_data)
00469 {
00470     Xi18n i18n_core = ims->protocol;
00471     FrameMgr fm;
00472     extern XimFrameRec str_conversion_fr[];
00473     int total_size;
00474     unsigned char *reply = NULL;
00475     IMStrConvCBStruct *call_back =
00476       (IMStrConvCBStruct*)&call_data->strconv_callback;
00477     XIMStringConversionCallbackStruct *strconv =
00478       (XIMStringConversionCallbackStruct *)&call_back->strconv;
00479     CARD16 connect_id = call_data->any.connect_id;
00480 
00481     /* create FrameMgr */
00482     fm = FrameMgrInit(str_conversion_fr, NULL,
00483                     _Xi18nNeedSwap(i18n_core, connect_id));
00484     total_size = FrameMgrGetTotalSize(fm);
00485     reply = (unsigned char *)malloc(total_size);
00486     if (!reply) {
00487        _Xi18nSendMessage(ims, connect_id, XIM_ERROR, 0, 0, 0);
00488        return False;
00489     }
00490     memset(reply, 0, total_size);
00491     FrameMgrSetBuffer(fm, reply);
00492 
00493     FrameMgrPutToken(fm, connect_id);
00494     FrameMgrPutToken(fm, call_back->icid);
00495     FrameMgrPutToken(fm, strconv->position);
00496     FrameMgrPutToken(fm, strconv->factor);
00497     FrameMgrPutToken(fm, strconv->direction);
00498     FrameMgrPutToken(fm, strconv->operation);
00499     _Xi18nSendMessage(ims, connect_id,
00500                     XIM_STR_CONVERSION, 0, reply, total_size);
00501     /* free FrameMgr */
00502     FrameMgrFree(fm);
00503     XFree(reply);
00504 
00505     /* XIM_STR_CONVERSION is a syncronous protocol,
00506        so should wait here for XIM_STR_CONVERSION_REPLY. */
00507     if (i18n_core->methods.wait(ims, connect_id,
00508                             XIM_STR_CONVERSION_REPLY, 0) == False)
00509       return False;
00510     return True;
00511 }