Back to index

im-sdk  12.3.91
IIIMPClientCB.cpp
Go to the documentation of this file.
00001 /*
00002 Copyright 1990-2001 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 #if !defined(USE_FRAMEMGR_ALWAYS)
00043 #else /* USE_FRAMEMGR_ALWAYS */
00044 #include "FrameMgr.h"
00045 #endif /* USE_FRAMEMGR_ALWAYS */
00046 #include "IIIMPClient.hh"
00047 #include "IMProtocolStruct.h"
00048 #include "IMProtocolStructP.hh"
00049 #include "IMTrans.hh"
00050 
00051 #if !defined(USE_FRAMEMGR_ALWAYS)
00052 int
00053 IIIMPClient::imtext_size(IMText *text) {
00054   IMFeedbackList *feedback;
00055   IMAnnotation *ann;
00056   int size;
00057   int i;
00058 
00059   if (NULL == text) {
00060     return (4 + 4);
00061   }
00062   size = 0;
00063   size += 4;  /* byte length of list of char_with_feedback */
00064   for (i = 0; i < text->char_length; i++) {
00065     feedback = (text->feedback + i);
00066     size += 2;       /* character element */
00067     size += 2;       /* byte length of Feedback attribute array */
00068     size += (8 * feedback->count_feedbacks);     /* feedback */
00069   }
00070   size += 4;  /* byte length of list of annotation */
00071   for (i = 0; i < text->count_annotations; i++) {
00072     ann = (text->annotations + i);
00073     size += 4;       /* attribute ID */
00074     size += 4;       /* byte length of list of annotation value */
00075     size += 4;       /* start index */
00076     size += 4;       /* byte length of value */
00077     if (ann->value.len & 0x03) {
00078       size += ((ann->value.len & (~0x03)) + 4);
00079     } else {
00080       size += ann->value.len;
00081     }
00082   }
00083   return size;
00084 }
00085 
00086 char *
00087 IIIMPClient::req_put_imtext(char * ptr, IMText * text) {
00088   IMFeedbackList *feedback;
00089   IMAnnotation *ann;
00090   int size;
00091   int i;
00092   int j;
00093   char *ptr_hold;
00094 
00095   if (NULL == text) {
00096     req_put32(ptr, 0);      /* byte length of list of char_with_feedback */
00097     req_put32(ptr, 0);      /* byte length of list of annotation */
00098     return ptr;
00099   }
00100 
00101   ptr_hold = ptr;
00102   req_put32(ptr, 0); /* dummy */
00103   size = 0;
00104   for (i = 0; i < text->char_length; i++) {
00105     feedback = (text->feedback + i);
00106     req_put16(ptr, *(text->text.utf_chars + i));
00107     req_put16(ptr, (8 * feedback->count_feedbacks));
00108     size += 4;
00109     for (j = 0; j < feedback->count_feedbacks; j++) {
00110       req_put32(ptr, (feedback->feedbacks + j)->type);
00111       req_put32(ptr, (feedback->feedbacks + j)->value);
00112       size += 8;
00113     }
00114   }
00115   req_put32(ptr_hold, size);
00116 
00117   ptr_hold = ptr;
00118   req_put32(ptr, 0); /* dummy */
00119   size = 0;
00120   for (i = 0; i < text->count_annotations; i++) {
00121     ann = (text->annotations + i);
00122     req_put32(ptr, ann->type);            /* attribute ID */
00123     req_put32(ptr, ann->value.len);       /* byte length of list of annotation value */
00124     req_put32(ptr, ann->value.start_pos); /* start index */
00125     req_put32(ptr, ann->value.end_pos);   /* byte length of value */
00126     size += (4 * 4);
00127     for (j = 0; j < ann->value.len; j++) {
00128       req_put8(ptr, *(((char *)(ann->value.value)) + j));
00129     }
00130     for (i = (ann->value.len & 0x03); 0 < i; i++) {
00131       req_put8(ptr, 0);
00132     }
00133     if (ann->value.len & 0x03) {
00134       size += ((ann->value.len & (~0x03)) + 4);
00135     } else {
00136       size += ann->value.len;
00137     }
00138   }
00139   req_put32(ptr_hold, size);
00140 
00141   return ptr;
00142 }
00143 
00144 char *
00145 IIIMPClient::req_put_imtext_s(char * ptr, IMText * text) {
00146   IMFeedbackList *feedback;
00147   IMAnnotation *ann;
00148   int size;
00149   int i;
00150   int j;
00151   char *ptr_hold;
00152 
00153   if (NULL == text) {
00154     req_put32s(ptr, 0);     /* byte length of list of char_with_feedback */
00155     req_put32s(ptr, 0);     /* byte length of list of annotation */
00156     return ptr;
00157   }
00158 
00159   ptr_hold = ptr;
00160   req_put32s(ptr, 0);       /* dummy */
00161   size = 0;
00162   for (i = 0; i < text->char_length; i++) {
00163     feedback = (text->feedback + i);
00164     req_put16s(ptr, *(text->text.utf_chars + i));
00165     req_put16s(ptr, (8 * feedback->count_feedbacks));
00166     size += 4;
00167     for (j = 0; j < feedback->count_feedbacks; j++) {
00168       req_put32s(ptr, (feedback->feedbacks + j)->type);
00169       req_put32s(ptr, (feedback->feedbacks + j)->value);
00170       size += 8;
00171     }
00172   }
00173   req_put32s(ptr_hold, size);
00174 
00175   ptr_hold = ptr;
00176   req_put32s(ptr, 0);       /* dummy */
00177   size = 0;
00178   for (i = 0; i < text->count_annotations; i++) {
00179     ann = (text->annotations + i);
00180     req_put32s(ptr, ann->type);           /* attribute ID */
00181     req_put32s(ptr, ann->value.len);      /* byte length of list of annotation value */
00182     req_put32s(ptr, ann->value.start_pos);       /* start index */
00183     req_put32s(ptr, ann->value.end_pos);  /* byte length of value */
00184     size += (4 * 4);
00185     for (j = 0; j < ann->value.len; j++) {
00186       req_put8s(ptr, *(((char *)(ann->value.value)) + j));
00187     }
00188     for (i = (ann->value.len & 0x03); 0 < i; i++) {
00189       req_put8s(ptr, 0);
00190     }
00191     if (ann->value.len & 0x03) {
00192       size += ((ann->value.len & (~0x03)) + 4);
00193     } else {
00194       size += ann->value.len;
00195     }
00196   }
00197   req_put32s(ptr_hold, size);
00198 
00199   return ptr;
00200 }
00201 
00202 int
00203 IIIMPClient::utf16_string_size(int len) {
00204   int size;
00205   size = 2;          /* byte length of LISTofCHAR */
00206   size += (2 * len); /* string */
00207   if (size & 0x02) { /* padding */
00208     size += 2;
00209   }
00210 
00211   return size;
00212 }
00213 
00214 char *
00215 IIIMPClient::req_put_utf16_string(char * ptr, UTFCHAR * string, int length) {
00216   int i;
00217   int j;
00218   char *ptr_hold;
00219 
00220   req_put16(ptr, (2 * length));
00221   for (i = 0; i < length; i++) {
00222     req_put16(ptr, *(string + i));
00223   }
00224   if (0 == (length & 0x01)) {
00225     req_put16(ptr, 0);             /* padding */
00226   }
00227   return ptr;
00228 }
00229 
00230 char *
00231 IIIMPClient::req_put_utf16_string_s(char * ptr, UTFCHAR * string, int length) {
00232   int i;
00233   int j;
00234   char *ptr_hold;
00235 
00236   req_put16s(ptr, (2 * length));
00237   for (i = 0; i < length; i++) {
00238     req_put16s(ptr, *(string + i));
00239   }
00240   if (0 == (length & 0x01)) {
00241     req_put16s(ptr, 0);            /* padding */
00242   }
00243   return ptr;
00244 }
00245 
00246 int
00247 IIIMPClient::ascii_string_size(char * string) {
00248   int size;
00249 
00250   size = 2;          /* byte length of LISTofCHAR */
00251   if (NULL != string) {     /* string */
00252     size += (2 * strlen(string));
00253   }
00254   if (size & 0x02) { /* padding */
00255     size += 2;
00256   }
00257   return size;
00258 }
00259 
00260 char *
00261 IIIMPClient::req_put_ascii_string(char * ptr, char * string) {
00262   int length;
00263   int i;
00264   int j;
00265   char *ptr_hold;
00266 
00267   if (NULL == string) {
00268     length = 0;
00269   } else {
00270     length = strlen(string);
00271   }
00272   req_put16(ptr, (2 * length));
00273   for (i = 0; i < length; i++) {
00274     req_put16(ptr, *(string + i));
00275   }
00276   if (0 == (length & 0x01)) {
00277     req_put16(ptr, 0);             /* padding */
00278   }
00279   return ptr;
00280 }
00281 
00282 char *
00283 IIIMPClient::req_put_ascii_string_s(char * ptr, char * string) {
00284   int length;
00285   int i;
00286   int j;
00287   char *ptr_hold;
00288 
00289   if (NULL == string) {
00290     length = 0;
00291   } else {
00292     length = strlen(string);
00293   }
00294   req_put16s(ptr, (2 * length));
00295   for (i = 0; i < length; i++) {
00296     req_put16s(ptr, *(string + i));
00297   }
00298   if (0 == (length & 0x01)) {
00299     req_put16s(ptr, 0);            /* padding */
00300   }
00301   return ptr;
00302 }
00303 
00304 #else /* USE_FRAMEMGR_ALWAYS */
00305 #endif /* USE_FRAMEMGR_ALWAYS */
00306 
00307 int
00308 IIIMPClient::commit_string(IMCommitCBStruct *commit_CB) {
00309 #if !defined(USE_FRAMEMGR_ALWAYS)
00310 #else /* USE_FRAMEMGR_ALWAYS */
00311   FrameMgr fm;
00312   extern XimFrameRec im_commit_string_string_fr[];
00313 #endif /* USE_FRAMEMGR_ALWAYS */
00314   IMText *text = commit_CB->text;
00315 
00316   if (!text || text->char_length == 0) {
00317     return True;     // no string to commit
00318   }
00319 
00320   int text_length = text->char_length;
00321   UTFCHAR *utf_chars;
00322 
00323   if (text->encoding == UTF16_CODESET) {
00324     utf_chars = text->text.utf_chars;
00325     if (*utf_chars == 0xfffe || *utf_chars == 0xfeff) {
00326       utf_chars++;
00327       text_length -= 1;
00328     }
00329   } else {
00330     utf_chars = 0;
00331   }
00332 
00333   /* without FrameMgr */
00334   int         total_length;
00335   int         str_len;
00336   int         contents_type;
00337   UTFCHAR *   ut;
00338   int         i;
00339 
00340   total_length = 0;
00341   contents_type = 0;        /* STRING */
00342 
00343   total_length += 2;        /* im_id */
00344   total_length += 2;        /* ic_id */
00345 
00346   total_length += 4;        /* contents type */
00347   total_length += 2;        /* byte length of string */
00348   str_len = (2 * text_length);     /* unicode code element */
00349   total_length += str_len;
00350   if (0 == (text_length % 2)) {
00351     total_length += 2; /* padding */
00352   }
00353 
00354   CompoundString request = CompoundString(total_length, 0);
00355   unsigned char * p;
00356 
00357   p = request.toUchar();
00358 
00359   if (False == need_swap) {
00360     req_put16(p, im_id);
00361     req_put16(p, commit_CB->icid);
00362     req_put32(p, contents_type);
00363     req_put16(p, str_len);
00364     for (i = 0, ut = utf_chars; i < text_length; i++, ut++) {
00365       req_put16(p, *ut);
00366     }
00367   } else {
00368     req_put16s(p, im_id);
00369     req_put16s(p, commit_CB->icid);
00370     req_put32s(p, contents_type);
00371     req_put16s(p, str_len);
00372     for (i = 0, ut = utf_chars; i < text_length; i++, ut++) {
00373       req_put16s(p, *ut);
00374     }
00375   }
00376 
00377   send_message(IM_COMMIT_STRING, request, total_length);
00378   return True;
00379 
00380 #if 0
00381   fm = FrameMgrInit(im_commit_string_string_fr, NULL, need_swap);
00382                   
00383   int text_length = text->char_length;
00384   UTFCHAR *utf_chars;
00385 
00386   if (text->encoding == UTF16_CODESET) {
00387     utf_chars = text->text.utf_chars;
00388     if (*utf_chars == 0xfffe || *utf_chars == 0xfeff) {
00389       utf_chars++;
00390       text_length -= 1;
00391     }
00392   } else {
00393 #ifdef DEBUG
00394     // cerr << "need to do convertion" << endl;
00395 #endif
00396     utf_chars = 0;
00397   }
00398   FrameMgrSetIterCount(fm, text_length);
00399   const int total_size = FrameMgrGetTotalSize(fm);
00400   CompoundString reply = CompoundString(total_size);
00401   memset(reply, 0, total_size);
00402   FrameMgrSetBuffer(fm, reply);
00403 
00404   int flag = 0;      /* #0 for STRING */
00405   FrameMgrPutToken(fm, im_id);
00406   FrameMgrPutToken(fm, commit_CB->icid);
00407   FrameMgrPutToken(fm, flag);
00408 
00409   SetStringToFrame(fm, utf_chars, text_length);
00410 
00411   send_message(IM_COMMIT_STRING, reply, total_size);
00412   /* free FrameMgr */
00413   FrameMgrFree(fm);
00414   return True;
00415 #endif /* 0 */
00416 }
00417 
00418 int
00419 IIIMPClient::forward_event(IMForwardEventCBStruct *event_CB) {
00420 #if !defined(USE_FRAMEMGR_ALWAYS)
00421   const int total_size = (4 + 2 + 2 + 4 + 4 + ((4 * 4) * 1));
00422   char data[total_size];
00423   char *ptr;
00424 #else /* USE_FRAMEMGR_ALWAYS */
00425   FrameMgr fm;
00426   extern XimFrameRec im_forward_event_keyevent_fr[];
00427 #endif /* USE_FRAMEMGR_ALWAYS */
00428 
00429 #if !defined(USE_FRAMEMGR_ALWAYS)
00430   ptr = (data + 4);
00431   if (False == need_swap) {
00432     req_put16(ptr, im_id); 
00433     req_put16(ptr, event_CB->icid);
00434     req_put32(ptr, 2);             /* KEYEVENT type = #02 */
00435     req_put32(ptr, 16);            /* one KEYEVENT */
00436     req_put32(ptr, event_CB->event->keyCode);
00437     req_put32(ptr, event_CB->event->keyChar);
00438     req_put32(ptr, event_CB->event->modifier);
00439     req_put32(ptr, event_CB->event->time_stamp);
00440   } else {
00441     req_put16s(ptr, im_id); 
00442     req_put16s(ptr, event_CB->icid);
00443     req_put32s(ptr, 2);            /* KEYEVENT type = #02 */
00444     req_put32s(ptr, 16);    /* one KEYEVENT */
00445     req_put32s(ptr, event_CB->event->keyCode);
00446     req_put32s(ptr, event_CB->event->keyChar);
00447     req_put32s(ptr, event_CB->event->modifier);
00448     req_put32s(ptr, event_CB->event->time_stamp);
00449   }
00450   send_message(IM_FORWARD_EVENT, data, (sizeof (data)));
00451 #else /* USE_FRAMEMGR_ALWAYS */
00452   fm = FrameMgrInit(im_forward_event_keyevent_fr, NULL, need_swap);
00453 
00454   int iter_count = 1;
00455   FrameMgrSetIterCount(fm, iter_count);
00456 
00457   const int total_size = FrameMgrGetTotalSize(fm);
00458   CompoundString reply = CompoundString(total_size);
00459   memset(reply, 0, total_size);
00460   FrameMgrSetBuffer(fm, reply);
00461 
00462   FrameMgrPutToken(fm, im_id);
00463   FrameMgrPutToken(fm, event_CB->icid);
00464   int type = 2; /* KEYEVENT type = #02 */
00465   FrameMgrPutToken(fm, type);
00466 
00467   IMKeyEventStruct *key = event_CB->event;
00468   FrameMgrPutToken(fm, key->keyCode);
00469   FrameMgrPutToken(fm, key->keyChar);
00470   FrameMgrPutToken(fm, key->modifier);
00471   FrameMgrPutToken(fm, key->time_stamp);
00472 
00473   send_message(IM_FORWARD_EVENT, reply, total_size);
00474 
00475   /* free FrameMgr */
00476   FrameMgrFree(fm);
00477 #endif /* USE_FRAMEMGR_ALWAYS */
00478 
00479   return True;
00480 }
00481 
00482 int IIIMPClient::preedit_start(IMPreeditCBStruct *preedit_CB) {
00483 #if !defined(USE_FRAMEMGR_ALWAYS)
00484   send_message(im_id, preedit_CB->icid, IM_PREEDIT_START);
00485 #else /* USE_FRAMEMGR_ALWAYS */
00486   extern XimFrameRec im_preedit_start_fr[];
00487   send_message(im_id, preedit_CB->icid,
00488               im_preedit_start_fr, IM_PREEDIT_START);
00489 #endif /* USE_FRAMEMGR_ALWAYS */
00490   return True;
00491 }
00492 
00493 int IIIMPClient::preedit_erase_text(IMPreeditCBStruct *preedit_CB) {
00494 #if !defined(USE_FRAMEMGR_ALWAYS)
00495   char data[4 + 2 + 2 + 4 + 4 + 4 + 4 + 4 + 4];
00496   char *ptr;
00497 #else /* USE_FRAMEMGR_ALWAYS */
00498   FrameMgr fm;
00499   extern XimFrameRec im_preedit_draw_string_fr[];
00500 #endif /* USE_FRAMEMGR_ALWAYS */
00501   IMPreeditDrawCallbackStruct *draw =
00502     (IMPreeditDrawCallbackStruct *)&preedit_CB->preedit->todo.draw;
00503   IMText *text = draw->text;
00504 
00505 #if !defined(USE_FRAMEMGR_ALWAYS)
00506   ptr = (data + 4);
00507   if (False == need_swap) {
00508     req_put16(ptr, im_id);
00509     req_put16(ptr, preedit_CB->icid);
00510     req_put32(ptr, draw->caret);
00511     req_put32(ptr, draw->chg_first);
00512     req_put32(ptr, draw->chg_length);
00513     req_put32(ptr, 1);      /* #1 for TEXT */
00514     req_put32(ptr, 0);      /* byte length of list of char_with_feedbac */
00515     req_put32(ptr, 0);      /* byte length of list of annotatio */
00516   } else {
00517     req_put16s(ptr, im_id);
00518     req_put16s(ptr, preedit_CB->icid);
00519     req_put32s(ptr, draw->caret);
00520     req_put32s(ptr, draw->chg_first);
00521     req_put32s(ptr, draw->chg_length);
00522     req_put32s(ptr, 1);     /* #1 for TEXT */
00523     req_put32s(ptr, 0);     /* byte length of list of char_with_feedbac */
00524     req_put32s(ptr, 0);     /* byte length of list of annotatio */
00525   }
00526   send_message(IM_PREEDIT_DRAW, data, (sizeof (data)));
00527 
00528 #else /* USE_FRAMEMGR_ALWAYS */
00529   /* create FrameMgr */
00530   fm = FrameMgrInit(im_preedit_draw_string_fr, NULL, need_swap);
00531 
00532   const int text_length = 0;
00533   FrameMgrSetIterCount(fm, text_length);
00534 
00535   const int total_size = FrameMgrGetTotalSize(fm);
00536   CompoundString reply = CompoundString(total_size);
00537   memset(reply, 0, total_size);
00538   FrameMgrSetBuffer(fm, reply);
00539 
00540   FrameMgrPutToken(fm, im_id);
00541   FrameMgrPutToken(fm, preedit_CB->icid);
00542   FrameMgrPutToken(fm, draw->caret);
00543   FrameMgrPutToken(fm, draw->chg_first);
00544   FrameMgrPutToken(fm, draw->chg_length);
00545   int flag = 1;      /* #1 for TEXT */
00546   FrameMgrPutToken(fm, flag);
00547 
00548   int annotation_len = 0;   /* annotation is not used */
00549   FrameMgrPutToken(fm, annotation_len); /* annotation_len = 0 */
00550 
00551   send_message(IM_PREEDIT_DRAW, reply, total_size);
00552   /* free FrameMgr */
00553   FrameMgrFree(fm);
00554 #endif /* USE_FRAMEMGR_ALWAYS */
00555   return True;
00556 }
00557 
00558 int IIIMPClient::preedit_draw_text(IMPreeditCBStruct *preedit_CB) {
00559 #if !defined(USE_FRAMEMGR_ALWAYS)
00560 #else /* USE_FRAMEMGR_ALWAYS */
00561   FrameMgr fm;
00562   extern XimFrameRec im_preedit_draw_text_fr[];
00563 #endif /* USE_FRAMEMGR_ALWAYS */
00564   IMPreeditDrawCallbackStruct *draw =
00565     (IMPreeditDrawCallbackStruct *)&preedit_CB->preedit->todo.draw;
00566   IMText *text = draw->text;
00567   int i, j;
00568 
00569   if (text->char_length == 0) {
00570     return True;     /* no string to draw */
00571   }
00572 
00573 #if !defined(USE_FRAMEMGR_ALWAYS)
00574   int text_length = text->char_length;
00575   UTFCHAR *utf_chars;
00576 
00577   if (text->encoding == UTF16_CODESET) {
00578     utf_chars = text->text.utf_chars;
00579     if (*utf_chars == 0xfffe || *utf_chars == 0xfeff) {
00580       utf_chars++;
00581       text_length -= 1;
00582     }
00583   } else {
00584     utf_chars = 0;
00585   }
00586 
00587   /* without FrameMgr */
00588   int         total_length;
00589   int         fa_len;
00590   int         cwf_len;
00591   int         annotation_len;
00592   int         contents_type;
00593   UTFCHAR *   ut;
00594 
00595   total_length = 0;
00596   fa_len = 0;
00597   cwf_len = 0;
00598   annotation_len = 0;
00599   contents_type = 1;        /* contents type #1 : TEXT */
00600 
00601   total_length += 4;        /* request header */
00602 
00603   total_length += 2;        /* im_id */
00604   total_length += 2;        /* ic_id */
00605   total_length += 4;        /* caret */
00606   total_length += 4;        /* change_first */
00607   total_length += 4;        /* change_length */
00608 
00609   total_length += 4;        /* contents type */
00610   total_length += 4;        /* byte length of list of char_with_feedback */
00611   cwf_len += (2 * text_length);    /* unicode code element */
00612   cwf_len += (2 * text_length);    /* byte length of Feedback attribute */
00613                                    /* array */
00614   for (i = 0; i < text_length; i++) {     /* feedback_attr */
00615     fa_len += (8 * (text->feedback + i)->count_feedbacks);
00616   }
00617   cwf_len += fa_len;
00618 
00619   total_length += cwf_len;
00620 
00621   total_length += 4;        /* byte length of list of annotation */
00622   total_length += 0;        /* annotation is not supported yet */
00623 
00624   char * request = new char[total_length];
00625   char * p;
00626 
00627   p = (request + 4);
00628 
00629   if (False == need_swap) {
00630     req_put16(p, im_id);
00631     req_put16(p, preedit_CB->icid);
00632     req_put32(p, draw->caret);
00633     req_put32(p, draw->chg_first);
00634     req_put32(p, draw->chg_length);
00635     req_put32(p, contents_type);
00636     req_put32(p, cwf_len);
00637     for (i = 0, ut = utf_chars; i < text_length; i++, ut++) {
00638       int cf;
00639       req_put16(p, *ut);
00640       cf = (text->feedback + i)->count_feedbacks;
00641       req_put16(p, (8 * cf));
00642       for (j = 0; j < cf; j++) {
00643        req_put32(p, ((text->feedback + i)->feedbacks + j)->type);
00644        req_put32(p, ((text->feedback + i)->feedbacks + j)->value);
00645       }
00646     }
00647     req_put32(p, annotation_len);  /* annotation is not supported yet */
00648   } else {
00649     req_put16s(p, im_id);
00650     req_put16s(p, preedit_CB->icid);
00651     req_put32s(p, draw->caret);
00652     req_put32s(p, draw->chg_first);
00653     req_put32s(p, draw->chg_length);
00654     req_put32s(p, contents_type);
00655     req_put32s(p, cwf_len);
00656     for (i = 0, ut = utf_chars; i < text_length; i++, ut++) {
00657       int cf;
00658       req_put16s(p, *ut);
00659       cf = (text->feedback + i)->count_feedbacks;
00660       req_put16s(p, (8 * cf));
00661       for (j = 0; j < cf; j++) {
00662        req_put32s(p, ((text->feedback + i)->feedbacks + j)->type);
00663        req_put32s(p, ((text->feedback + i)->feedbacks + j)->value);
00664       }
00665     }
00666     req_put32s(p, annotation_len); /* annotation is not supported yet */
00667   }
00668 
00669   send_message(IM_PREEDIT_DRAW, request, total_length);
00670 
00671   delete [] request;
00672 
00673   return True;
00674 
00675 #else /* USE_FRAMEMGR_ALWAYS */
00676   /* create FrameMgr */
00677   fm = FrameMgrInit(im_preedit_draw_text_fr, NULL, need_swap);
00678        
00679   int text_length = text->char_length;
00680   UTFCHAR *utf_chars;
00681 
00682   if (text->encoding == UTF16_CODESET) {
00683     utf_chars = text->text.utf_chars;
00684     if (*utf_chars == 0xfffe || *utf_chars == 0xfeff) {
00685       utf_chars++;
00686       text_length -= 1;
00687     }
00688   } else {
00689 #ifdef DEBUG
00690     // cerr << "need to do convertion" << endl;
00691 #endif
00692     utf_chars = 0;
00693   }
00694   FrameMgrSetIterCount(fm, text_length);
00695 
00696   if (text != NULL) {
00697     for (i = 0; i < text_length; i++) {
00698       IMFeedbackList *fbl = &(text->feedback[i]);
00699       // set iteration count for list of feedback
00700       FrameMgrSetIterCount(fm, fbl->count_feedbacks);
00701     }
00702   }
00703 
00704   const int total_size = FrameMgrGetTotalSize(fm);
00705   CompoundString reply = CompoundString(total_size);
00706   memset(reply, 0, total_size);
00707   FrameMgrSetBuffer(fm, reply);
00708     
00709   FrameMgrPutToken(fm, im_id);
00710   FrameMgrPutToken(fm, preedit_CB->icid);
00711   FrameMgrPutToken(fm, draw->caret);
00712   FrameMgrPutToken(fm, draw->chg_first);
00713   FrameMgrPutToken(fm, draw->chg_length);
00714   int flag = 1;                    /* #1 for TEXT */
00715   FrameMgrPutToken(fm, flag);
00716 
00717   CARD8 *utf_str = (CARD8*)utf_chars;
00718   CARD8 *strp = utf_str;
00719 
00720   const int one_unit = sizeof(UTFCHAR)/sizeof(char);
00721   for (i = 0; i < text_length, strp < &utf_str[text_length * one_unit];
00722        i++) {
00723     CARD8 first_byte, second_byte;
00724     if (need_swap) {
00725       second_byte = *strp++;
00726       first_byte = *strp++;
00727     } else {
00728       first_byte = *strp++;
00729       second_byte = *strp++;
00730     }
00731     FrameMgrPutToken(fm, first_byte);
00732     FrameMgrPutToken(fm, second_byte);
00733 
00734     if (text != NULL) {
00735        IMFeedbackList *fbl = &(text->feedback[i]);
00736         for (j = 0; j < fbl->count_feedbacks; j++){
00737          IMFeedback *fb = &(fbl->feedbacks[j]);
00738          FrameMgrPutToken(fm, fb->type);
00739          FrameMgrPutToken(fm, fb->value);
00740        }
00741     }
00742   }
00743   int annotation_len = 0;   /* annotation is not used */
00744   FrameMgrPutToken(fm, annotation_len); /* annotation_len = 0 */
00745 
00746   send_message(IM_PREEDIT_DRAW, reply, total_size);
00747   /* free FrameMgr */
00748   FrameMgrFree(fm);
00749 
00750   return True;
00751 #endif /* USE_FRAMEMGR_ALWAYS */
00752 }
00753 
00754 int IIIMPClient::preedit_draw(IMPreeditCBStruct *preedit_CB) {
00755   IMPreeditDrawCallbackStruct *draw =
00756     (IMPreeditDrawCallbackStruct *)&preedit_CB->preedit->todo.draw;
00757   int ret;
00758 
00759   if (draw->text == NULL || draw->text->char_length == 0) {
00760     ret = preedit_erase_text(preedit_CB);
00761   } else {
00762     ret = preedit_draw_text(preedit_CB);
00763   }
00764   return ret;
00765 }
00766 
00767 int IIIMPClient::preedit_caret(IMPreeditCBStruct *preedit_CB) {
00768 #if !defined(USE_FRAMEMGR_ALWAYS)
00769   char data[4 + 2 + 2 + 4 + 4 + 4];
00770   char *ptr;
00771 #else /* USE_FRAMEMGR_ALWAYS */
00772   FrameMgr fm;
00773   extern XimFrameRec im_preedit_caret_fr[];
00774 #endif /* USE_FRAMEMGR_ALWAYS */
00775   IMPreeditCaretCallbackStruct *caret =
00776     (IMPreeditCaretCallbackStruct *)&preedit_CB->preedit->todo.caret;
00777 
00778 #if !defined(USE_FRAMEMGR_ALWAYS)
00779   ptr = (data + 4);
00780   if (False == need_swap) {
00781     req_put16(ptr, im_id);
00782     req_put16(ptr, preedit_CB->icid);
00783     req_put32(ptr, caret->position);
00784     req_put32(ptr, caret->direction);
00785     req_put32(ptr, caret->style);
00786   } else {
00787     req_put16s(ptr, im_id);
00788     req_put16s(ptr, preedit_CB->icid);
00789     req_put32s(ptr, caret->position);
00790     req_put32s(ptr, caret->direction);
00791     req_put32s(ptr, caret->style);
00792   }
00793   send_message(IM_PREEDIT_CARET, data, (sizeof (data)));
00794 #else /* USE_FRAMEMGR_ALWAYS */
00795   /* create FrameMgr */
00796   fm = FrameMgrInit(im_preedit_caret_fr, NULL, need_swap);
00797 
00798   const int total_size = FrameMgrGetTotalSize(fm);
00799   CompoundString reply = CompoundString(total_size);
00800   memset(reply, 0, total_size);
00801   FrameMgrSetBuffer(fm, reply);
00802 
00803   FrameMgrPutToken(fm, im_id);
00804   FrameMgrPutToken(fm, preedit_CB->icid);
00805   FrameMgrPutToken(fm, caret->position);
00806   FrameMgrPutToken(fm, caret->direction);
00807   FrameMgrPutToken(fm, caret->style);
00808 
00809   send_message(IM_PREEDIT_CARET, reply, total_size);
00810   /* free FrameMgr */
00811   FrameMgrFree(fm);
00812 #endif /* USE_FRAMEMGR_ALWAYS */
00813   return True;
00814 }
00815 
00816 int IIIMPClient::preedit_done(IMPreeditCBStruct *preedit_CB) {
00817 #if !defined(USE_FRAMEMGR_ALWAYS)
00818   send_message(im_id, preedit_CB->icid, IM_PREEDIT_DONE);
00819 #else /* USE_FRAMEMGR_ALWAYS */
00820   extern XimFrameRec im_preedit_done_fr[];
00821   send_message(im_id, preedit_CB->icid,
00822               im_preedit_done_fr, IM_PREEDIT_DONE);
00823 #endif /* USE_FRAMEMGR_ALWAYS */
00824   return True;
00825 }
00826 
00827 int IIIMPClient::status_start(IMStatusCBStruct *status_CB) {
00828 #if !defined(USE_FRAMEMGR_ALWAYS)
00829   send_message(im_id, status_CB->icid, IM_STATUS_START);
00830 #else /* USE_FRAMEMGR_ALWAYS */
00831   extern XimFrameRec im_status_start_fr[];
00832   send_message(im_id, status_CB->icid,
00833               im_status_start_fr, IM_STATUS_START);
00834 #endif /* USE_FRAMEMGR_ALWAYS */
00835   return True;
00836 }
00837 
00838 int IIIMPClient::status_draw_string(IMStatusCBStruct *status_CB) {
00839 #if !defined(USE_FRAMEMGR_ALWAYS)
00840   char *data;
00841   char buf[256];
00842   char *ptr;
00843   int total_size;
00844 #else /* USE_FRAMEMGR_ALWAYS */
00845   FrameMgr fm;
00846   extern XimFrameRec im_status_draw_string_fr[];
00847 #endif /* USE_FRAMEMGR_ALWAYS */
00848   IMStatusDrawCallbackStruct *draw =
00849     (IMStatusDrawCallbackStruct *)&status_CB->status->todo.draw;
00850   IMText *text = draw->text;
00851 
00852   if (text->char_length == 0) {
00853     return True;     /* no string to commit */
00854   }
00855 
00856 #if !defined(USE_FRAMEMGR_ALWAYS)
00857 #else /* USE_FRAMEMGR_ALWAYS */
00858   /* create FrameMgr */
00859   fm = FrameMgrInit(im_status_draw_string_fr, NULL, need_swap);
00860 #endif /* USE_FRAMEMGR_ALWAYS */
00861                   
00862   int text_length = text->char_length;
00863   UTFCHAR *utf_chars;
00864 
00865   if (text->encoding == UTF16_CODESET) {
00866     utf_chars = text->text.utf_chars;
00867     if (*utf_chars == 0xfffe || *utf_chars == 0xfeff) {
00868       utf_chars++;
00869       text_length -= 1;
00870     }
00871   } else {
00872 #ifdef DEBUG
00873     // cerr << "need to do convertion" << endl;
00874 #endif
00875     utf_chars = 0;
00876   }
00877 #if !defined(USE_FRAMEMGR_ALWAYS)
00878   total_size = 4;           /* IIIMP header */
00879   total_size += (2 + 2);    /* imid + icid */
00880   total_size += 4;          /* type of CONTENTS */
00881   total_size += 2;          /* byte length of string */
00882   total_size += (2 * text_length);
00883   if (total_size & 0x02) {  /* padding */
00884     total_size += 2;
00885   }
00886   if ((sizeof (buf)) < total_size) {
00887     data = new char[total_size];
00888   } else {
00889     data = buf;
00890   }
00891   ptr = (data + 4);
00892   if (False == need_swap) {
00893     req_put16(ptr, im_id);
00894     req_put16(ptr, status_CB->icid);
00895     req_put32(ptr, 0);             /* #0 for STRING */
00896     for (int i = 0; i < text_length; i++) {
00897       req_put16(ptr, *(utf_chars + i));
00898     }
00899   } else {
00900     req_put16s(ptr, im_id);
00901     req_put16s(ptr, status_CB->icid);
00902     req_put32s(ptr, 0);            /* #0 for STRING */
00903     for (int i = 0; i < text_length; i++) {
00904       req_put16s(ptr, *(utf_chars + i));
00905     }
00906   }
00907   if (total_size & 0x02) {  /* padding */
00908     req_put16(ptr, 0);             /* no need to swap byte */
00909   }
00910   send_message(IM_STATUS_DRAW, data, total_size);
00911   if ((sizeof (buf)) < total_size) {
00912     delete [] data;
00913   }
00914 #else /* USE_FRAMEMGR_ALWAYS */
00915   FrameMgrSetIterCount(fm, text_length);
00916 
00917   const int total_size = FrameMgrGetTotalSize(fm);
00918   CompoundString reply = CompoundString(total_size);
00919   memset(reply, 0, total_size);
00920   FrameMgrSetBuffer(fm, reply);
00921 
00922   int flag = 0;      /* #0 for STRING */
00923   FrameMgrPutToken(fm, im_id);
00924   FrameMgrPutToken(fm, status_CB->icid);
00925   FrameMgrPutToken(fm, flag);
00926 
00927   SetStringToFrame(fm, utf_chars, text_length);
00928 
00929   send_message(IM_STATUS_DRAW, reply, total_size);
00930   /* free FrameMgr */
00931   FrameMgrFree(fm);
00932 #endif /* USE_FRAMEMGR_ALWAYS */
00933   return True;
00934 }
00935 int IIIMPClient::status_draw_text(IMStatusCBStruct *status_CB) {
00936 #if !defined(USE_FRAMEMGR_ALWAYS)
00937 #else /* USE_FRAMEMGR_ALWAYS */
00938   FrameMgr fm;
00939   extern XimFrameRec im_status_draw_text_fr[];
00940 #endif /* USE_FRAMEMGR_ALWAYS */
00941   IMStatusDrawCallbackStruct *draw =
00942     (IMStatusDrawCallbackStruct *)&status_CB->status->todo.draw;
00943   IMText *text = draw->text;
00944   int i, j;
00945 
00946 #if !defined(USE_FRAMEMGR_ALWAYS)
00947   int text_length = text->char_length;
00948   UTFCHAR *utf_chars;
00949 
00950   if (text->encoding == UTF16_CODESET) {
00951     utf_chars = text->text.utf_chars;
00952     if (*utf_chars == 0xfffe || *utf_chars == 0xfeff) {
00953       utf_chars++;
00954       text_length -= 1;
00955     }
00956   } else {
00957     utf_chars = 0;
00958   }
00959 
00960   /* without FrameMgr */
00961   int         total_length;
00962   int         fa_len;
00963   int         cwf_len;
00964   int         annotation_len;
00965   int         contents_type;
00966   UTFCHAR *   ut;
00967 
00968 
00969   total_length = 0;
00970   fa_len = 0;
00971   cwf_len = 0;
00972   annotation_len = 0;
00973   contents_type = 1;        /* contents type #1 : TEXT */
00974 
00975   total_length += 4;        /* request header */
00976 
00977   total_length += 2;        /* im_id */
00978   total_length += 2;        /* ic_id */
00979 
00980   total_length += 4;        /* contents type */
00981   total_length += 4;        /* byte length of list of char_with_feedback */
00982   cwf_len += (2 * text_length);    /* unicode code element */
00983   cwf_len += (2 * text_length);    /* byte length of Feedback attribute */
00984                                    /* array */
00985   for (i = 0; i < text_length; i++) {     /* feedback_attr */
00986     fa_len += (8 * (text->feedback + i)->count_feedbacks);
00987   }
00988   cwf_len += fa_len;
00989 
00990   total_length += cwf_len;
00991 
00992   total_length += 4;        /* byte length of list of annotation */
00993   total_length += 0;        /* annotation is not supported yet */
00994 
00995   char * request;
00996   char * p;
00997 
00998   request = new char[total_length];
00999   p = (request + 4);
01000 
01001   if (False == need_swap) {
01002     req_put16(p, im_id);
01003     req_put16(p, status_CB->icid);
01004     req_put32(p, contents_type);
01005     req_put32(p, cwf_len);
01006     for (i = 0, ut = utf_chars; i < text_length; i++, ut++) {
01007       int cf;
01008       req_put16(p, *ut);
01009       cf = (text->feedback + i)->count_feedbacks;
01010       req_put16(p, (8 * cf));
01011       for (j = 0; j < cf; j++) {
01012        req_put32(p, ((text->feedback + i)->feedbacks + j)->type);
01013        req_put32(p, ((text->feedback + i)->feedbacks + j)->value);
01014       }
01015     }
01016     req_put32(p, annotation_len);  /* annotation is not supported yet */
01017   } else {
01018     req_put16s(p, im_id);
01019     req_put16s(p, status_CB->icid);
01020     req_put32s(p, contents_type);
01021     req_put32s(p, cwf_len);
01022     for (i = 0, ut = utf_chars; i < text_length; i++, ut++) {
01023       int cf;
01024       req_put16s(p, *ut);
01025       cf = (text->feedback + i)->count_feedbacks;
01026       req_put16s(p, (8 * cf));
01027       for (j = 0; j < cf; j++) {
01028        req_put32s(p, ((text->feedback + i)->feedbacks + j)->type);
01029        req_put32s(p, ((text->feedback + i)->feedbacks + j)->value);
01030       }
01031     }
01032     req_put32s(p, annotation_len); /* annotation is not supported yet */
01033   }
01034 
01035   send_message(IM_STATUS_DRAW, request, total_length);
01036 
01037   delete [] request;
01038 
01039   return True;
01040 
01041 #else /* USE_FRAMEMGR_ALWAYS */
01042   /* create FrameMgr */
01043   fm = FrameMgrInit(im_status_draw_text_fr, NULL, need_swap);
01044 
01045   int text_length = text->char_length;
01046   UTFCHAR *utf_chars;
01047 
01048   if (text->encoding == UTF16_CODESET) {
01049     utf_chars = text->text.utf_chars;
01050     if (*utf_chars == 0xfffe || *utf_chars == 0xfeff) {
01051       utf_chars++;
01052       text_length -= 1;
01053     }
01054   } else {
01055 #ifdef DEBUG
01056     // cerr << "need to do convertion" << endl;
01057 #endif
01058     utf_chars = 0;
01059   }
01060   FrameMgrSetIterCount(fm, text_length);
01061 
01062   if (draw->text != NULL) {
01063     for (i = 0; i < text_length; i++) {
01064       IMFeedbackList *fbl = &(draw->text->feedback[i]);
01065       // set iteration count for list of feedback
01066       FrameMgrSetIterCount(fm, fbl->count_feedbacks);
01067     }
01068   }
01069 
01070   const int total_size = FrameMgrGetTotalSize(fm);
01071   CompoundString reply = CompoundString(total_size);
01072   memset(reply, 0, total_size);
01073   FrameMgrSetBuffer(fm, reply);
01074     
01075   FrameMgrPutToken(fm, im_id);
01076   FrameMgrPutToken(fm, status_CB->icid);
01077   int flag = 1;                    /* #1 for TEXT */
01078   FrameMgrPutToken(fm, flag);
01079 
01080   CARD8 *utf_str = (CARD8*)utf_chars;
01081 
01082   CARD8 *strp = utf_str;
01083   const int one_unit = sizeof(UTFCHAR)/sizeof(char);
01084   for (i = 0; i < text_length, strp < &utf_str[text_length * one_unit];
01085        i++) {
01086     CARD8 first_byte, second_byte;
01087     if (need_swap) {
01088       second_byte = *strp++;
01089       first_byte  = *strp++;
01090     } else {
01091       first_byte  = *strp++;
01092       second_byte = *strp++;
01093     }
01094     FrameMgrPutToken(fm, first_byte);
01095     FrameMgrPutToken(fm, second_byte);
01096 
01097     if (text != NULL) {
01098        IMFeedbackList *fbl = &(text->feedback[i]);
01099         for (j = 0; j < fbl->count_feedbacks; j++){
01100          IMFeedback *fb = &(fbl->feedbacks[j]);
01101          FrameMgrPutToken(fm, fb->type);
01102          FrameMgrPutToken(fm, fb->value);
01103        }
01104     }
01105   }
01106   int annotation_len = 0; /* annotation is not used */
01107   FrameMgrPutToken(fm, annotation_len); /* annotation_len = 0 */
01108 
01109   send_message(IM_STATUS_DRAW, reply, total_size);
01110   /* free FrameMgr */
01111   FrameMgrFree(fm);
01112 
01113   return True;
01114 #endif /* USE_FRAMEMGR_ALWAYS */
01115 }
01116 
01117 int IIIMPClient::status_draw(IMStatusCBStruct *status_CB) {
01118   IMStatusDrawCallbackStruct *draw =
01119     (IMStatusDrawCallbackStruct *)&status_CB->status->todo.draw;
01120 
01121   if (draw->text != NULL && draw->text->char_length == 0)
01122     return status_draw_string(status_CB);
01123   else
01124     return status_draw_text(status_CB);
01125 
01126   return False;
01127 }
01128 
01129 int IIIMPClient::status_done(IMStatusCBStruct *status_CB) {
01130 #if !defined(USE_FRAMEMGR_ALWAYS)
01131   send_message(im_id, status_CB->icid, IM_STATUS_DONE);
01132 #else /* USE_FRAMEMGR_ALWAYS */
01133   extern XimFrameRec im_status_done_fr[];
01134   send_message(im_id,
01135               status_CB->icid,
01136               im_status_done_fr, IM_STATUS_DONE);
01137 #endif /* USE_FRAMEMGR_ALWAYS */
01138   return True;
01139 }
01140 
01141 int IIIMPClient::lookup_start(IMLookupCBStruct *lookup_CB) {
01142 #if !defined(USE_FRAMEMGR_ALWAYS)
01143   char data[4 + 2 + 2 + 2 + 2 + 2 + 2 + 2 + 2];
01144   char *ptr;
01145 #else /* USE_FRAMEMGR_ALWAYS */
01146   FrameMgr fm;
01147   extern XimFrameRec im_lookup_start_fr[];
01148 #endif /* USE_FRAMEMGR_ALWAYS */
01149   LayoutInfo *layout = (LayoutInfo *)0;
01150   IMLookupStartCallbackStruct *start =
01151     (IMLookupStartCallbackStruct*)&lookup_CB->lookup->todo.start;
01152   if (start->whoIsMaster == IMIsMaster)
01153      layout = start->IMPreference;
01154   else if (start->whoIsMaster == CBIsMaster) 
01155           layout = start->CBPreference;
01156        else 
01157          return False;
01158 
01159 #if !defined(USE_FRAMEMGR_ALWAYS)
01160   ptr = (data + 4);
01161   if (False == need_swap) {
01162     req_put16(ptr, im_id);
01163     req_put16(ptr, lookup_CB->icid);
01164     req_put16(ptr, start->whoIsMaster);
01165     req_put16(ptr, layout->choice_per_window);
01166     req_put16(ptr, layout->nrows);
01167     req_put16(ptr, layout->ncolumns);
01168     req_put16(ptr, layout->drawUpDirection);
01169     req_put16(ptr, layout->whoOwnsLabel);
01170   } else {
01171     req_put16s(ptr, im_id);
01172     req_put16s(ptr, lookup_CB->icid);
01173     req_put16s(ptr, start->whoIsMaster);
01174     req_put16s(ptr, layout->choice_per_window);
01175     req_put16s(ptr, layout->nrows);
01176     req_put16s(ptr, layout->ncolumns);
01177     req_put16s(ptr, layout->drawUpDirection);
01178     req_put16s(ptr, layout->whoOwnsLabel);
01179   }
01180   send_message(IM_LOOKUP_START, data, (sizeof (data)));
01181 #else /* USE_FRAMEMGR_ALWAYS */
01182   /* create FrameMgr */
01183   fm = FrameMgrInit(im_lookup_start_fr, NULL, need_swap);
01184               
01185   const int total_size = FrameMgrGetTotalSize(fm);
01186   CompoundString reply = CompoundString(total_size);
01187   memset(reply, 0, total_size);
01188   FrameMgrSetBuffer(fm, reply);
01189 
01190   FrameMgrPutToken(fm, im_id);
01191   FrameMgrPutToken(fm, lookup_CB->icid);
01192   FrameMgrPutToken(fm, start->whoIsMaster);
01193   FrameMgrPutToken(fm, layout->choice_per_window);
01194   FrameMgrPutToken(fm, layout->nrows);
01195   FrameMgrPutToken(fm, layout->ncolumns);
01196   FrameMgrPutToken(fm, layout->drawUpDirection);
01197   FrameMgrPutToken(fm, layout->whoOwnsLabel);
01198 
01199   send_message(IM_LOOKUP_START, reply, total_size);
01200   /* free FrameMgr */
01201   FrameMgrFree(fm);
01202 #endif /* USE_FRAMEMGR_ALWAYS */
01203 
01204   return True;
01205 }
01206 
01207 int IIIMPClient::lookup_draw(IMLookupCBStruct *lookup_CB) {
01208 #if !defined(USE_FRAMEMGR_ALWAYS)
01209   char *data;
01210   char *ptr;
01211   int total_size;
01212   int choice_list_size;
01213   int label_list_size;
01214   int title_size;
01215 #else /* USE_FRAMEMGR_ALWAYS */
01216   FrameMgr fm;
01217   extern XimFrameRec im_lookup_draw_fr[];
01218 #endif /* USE_FRAMEMGR_ALWAYS */
01219   IMLookupDrawCallbackStruct *draw =
01220     (IMLookupDrawCallbackStruct *)&lookup_CB->lookup->todo.draw;
01221   int i, j;
01222 
01223 #if !defined(USE_FRAMEMGR_ALWAYS)
01224   choice_list_size = 0;
01225   for (i = 0; i < draw->n_choices; i++) {  /* choice list */
01226     choice_list_size += imtext_size((draw->choices + i)->value);
01227   }
01228   label_list_size = 0;
01229   if (NULL != draw->choices->label) {     /* index label list */
01230     for (i = 0; i < draw->n_choices; i++) {
01231       label_list_size += imtext_size((draw->choices + i)->label);
01232     }
01233   }
01234   title_size = imtext_size(draw->title);  /* title */
01235 
01236   total_size = 4;    /* IIIMP header */
01237   total_size += (2 + 2);
01238   total_size += 4;   /* index of first candidate */
01239   total_size += 4;   /* index of last candidate */
01240   total_size += 4;   /* index of current candidate */
01241   total_size += 4;   /* byte length of choice list */
01242   total_size += choice_list_size;  /* choice list */
01243   total_size += 4;   /* byte length of index label list */
01244   total_size += label_list_size;   /* index label list */
01245   total_size += title_size;        /* title */
01246 
01247   data = new char[total_size];
01248   ptr = (data + 4);
01249 
01250   if (False == need_swap) {
01251     req_put16(ptr, im_id);
01252     req_put16(ptr, lookup_CB->icid);
01253     req_put32(ptr, draw->index_of_first_candidate);
01254     req_put32(ptr, draw->index_of_last_candidate);
01255     req_put32(ptr, draw->index_of_current_candidate);
01256     req_put32(ptr, choice_list_size);
01257     for (i = 0; i < draw->n_choices; i++) {  /* choice list */
01258       ptr = req_put_imtext(ptr, (draw->choices + i)->value);
01259     }
01260     req_put32(ptr, label_list_size);
01261     for (i = 0; i < draw->n_choices; i++) {  /* choice list */
01262       ptr = req_put_imtext(ptr, (draw->choices + i)->label);
01263     }
01264     ptr = req_put_imtext(ptr, draw->title);
01265   } else {
01266     req_put16s(ptr, im_id);
01267     req_put16s(ptr, lookup_CB->icid);
01268     req_put32s(ptr, draw->index_of_first_candidate);
01269     req_put32s(ptr, draw->index_of_last_candidate);
01270     req_put32s(ptr, draw->index_of_current_candidate);
01271     req_put32s(ptr, choice_list_size);
01272     for (i = 0; i < draw->n_choices; i++) {  /* choice list */
01273       ptr = req_put_imtext_s(ptr, (draw->choices + i)->value);
01274     }
01275     req_put32s(ptr, label_list_size);
01276     for (i = 0; i < draw->n_choices; i++) {  /* choice list */
01277       ptr = req_put_imtext_s(ptr, (draw->choices + i)->label);
01278     }
01279     ptr = req_put_imtext_s(ptr, draw->title);
01280   }
01281 
01282   send_message(IM_LOOKUP_DRAW, data, total_size);
01283 
01284   delete [] data;
01285 
01286 #else /* USE_FRAMEMGR_ALWAYS */
01287   /* create FrameMgr */
01288   fm = FrameMgrInit(im_lookup_draw_fr, NULL, need_swap);
01289 
01290   FrameMgrSetIterCount(fm, draw->n_choices);
01291 
01292   /* set iteration count for choice list */
01293   IMChoiceObject *choicep;
01294   for (choicep = draw->choices;
01295        choicep < &draw->choices[draw->n_choices]; choicep++) {
01296     FrameMgrSetIterCount(fm, choicep->value->char_length);
01297     for (i = 0; i < choicep->value->char_length; i++) {
01298       IMFeedbackList *fbl = &(choicep->value->feedback[i]);
01299       // set iteration count for list of feedback
01300       FrameMgrSetIterCount(fm, fbl->count_feedbacks);
01301     }
01302   }
01303 
01304   /* set iteration count for index label list */
01305   if (draw->choices->label == 0) {
01306     FrameMgrSetIterCount(fm, 0); /* no label strings */
01307   } else {
01308     FrameMgrSetIterCount(fm, draw->n_choices);
01309     for (choicep = draw->choices;
01310         choicep < &draw->choices[draw->n_choices]; choicep++) {
01311       FrameMgrSetIterCount(fm, choicep->label->char_length);
01312       for (i = 0; i < choicep->label->char_length; i++) {
01313        IMFeedbackList *fbl = &(choicep->label->feedback[i]);
01314        // set iteration count for list of feedback
01315        FrameMgrSetIterCount(fm, fbl->count_feedbacks);
01316       }
01317     }
01318   }
01319 
01320   if (draw->title == 0) {
01321     FrameMgrSetIterCount(fm, 0); /* no title */
01322   } else {
01323     FrameMgrSetIterCount(fm, draw->title->char_length);
01324     /* set iteration count for title */
01325     for (i = 0; i < draw->title->char_length; i++) {
01326       IMFeedbackList *fbl = &(draw->title->feedback[i]);
01327       // set iteration count for list of feedback
01328       FrameMgrSetIterCount(fm, fbl->count_feedbacks);
01329     }
01330   }
01331 
01332   /* get total_size */
01333   const int total_size = FrameMgrGetTotalSize(fm);
01334   CompoundString reply = CompoundString(total_size);
01335   memset(reply, 0, total_size);
01336   FrameMgrSetBuffer(fm, reply);
01337 
01338   FrameMgrPutToken(fm, im_id);
01339   FrameMgrPutToken(fm, lookup_CB->icid);
01340   FrameMgrPutToken(fm, draw->index_of_first_candidate);
01341   FrameMgrPutToken(fm, draw->index_of_last_candidate);
01342   FrameMgrPutToken(fm, draw->index_of_current_candidate);
01343 
01344   /* choice list */
01345   UTFCHAR *utf_chars;
01346   for (choicep = draw->choices;
01347        choicep < &draw->choices[draw->n_choices]; choicep++) {
01348     if (choicep->value->encoding == UTF16_CODESET) {
01349       utf_chars = choicep->value->text.utf_chars;
01350     } else {
01351 #ifdef DEBUG
01352       // cerr << "need to do convertion" << endl;
01353 #endif
01354       utf_chars = 0;
01355     }
01356     CARD8 first_byte, second_byte;
01357     CARD8 *utf_str = (CARD8*)utf_chars;
01358     CARD8 *strp = utf_str;
01359 
01360     for (i = 0; i < choicep->value->char_length; i++) {
01361       if (need_swap) {
01362        second_byte = *strp++;
01363        first_byte = *strp++;
01364       } else {
01365        first_byte = *strp++;
01366        second_byte = *strp++;
01367       }
01368       FrameMgrPutToken(fm, first_byte);
01369       FrameMgrPutToken(fm, second_byte);
01370 
01371       if (choicep->value != NULL) {
01372        IMFeedbackList *fbl = &(choicep->value->feedback[i]);
01373        for (j = 0; j < fbl->count_feedbacks; j++){
01374          IMFeedback *fb = &(fbl->feedbacks[j]);
01375          FrameMgrPutToken(fm, fb->type);
01376          FrameMgrPutToken(fm, fb->value);
01377        }
01378       }
01379     }
01380     int annotation_len = 0;
01381     FrameMgrPutToken(fm, annotation_len); /* annotation_len = 0 */
01382   }
01383 
01384   /* index label list */
01385   if (draw->choices->label != 0) {
01386     for (choicep = draw->choices;
01387         choicep < &draw->choices[draw->n_choices]; choicep++) {
01388       if (choicep->label->encoding == UTF16_CODESET) {
01389        utf_chars = choicep->label->text.utf_chars;
01390       } else {
01391 #ifdef DEBUG
01392        // cerr << "need to do convertion" << endl;
01393 #endif
01394        utf_chars = 0;
01395       }
01396       CARD8 first_byte, second_byte;
01397       CARD8 *utf_str = (CARD8*)utf_chars;
01398       CARD8 *strp = utf_str;
01399       for (i = 0; i < choicep->label->char_length; i++) {
01400        if (need_swap) {
01401          second_byte = *strp++;
01402          first_byte =  *strp++;
01403        } else {
01404          first_byte = *strp++;
01405          second_byte = *strp++;
01406        }
01407        FrameMgrPutToken(fm, first_byte);
01408        FrameMgrPutToken(fm, second_byte);
01409 
01410        if (choicep->label != NULL) {
01411          IMFeedbackList *fbl = &(choicep->label->feedback[i]);
01412          for (j = 0; j < fbl->count_feedbacks; j++){
01413            IMFeedback *fb = &(fbl->feedbacks[j]);
01414            FrameMgrPutToken(fm, fb->type);
01415            FrameMgrPutToken(fm, fb->value);
01416          }
01417        }
01418       }
01419       int annotation_len = 0;
01420       FrameMgrPutToken(fm, annotation_len); /* annotation_len = 0 */
01421     }
01422   }
01423 
01424   /* title */
01425   if (draw->title != 0) {
01426     if (draw->title->encoding == UTF16_CODESET) {
01427       utf_chars = draw->title->text.utf_chars;
01428     } else {
01429 #ifdef DEBUG
01430       // cerr << "need to do convertion" << endl;
01431 #endif
01432       utf_chars = 0;
01433     }
01434     CARD8 first_byte, second_byte;
01435     CARD8 *utf_str = (CARD8*)utf_chars;
01436     CARD8 *strp = utf_str;
01437     for (i = 0; i < draw->title->char_length; i++) {
01438       if (need_swap) {
01439        second_byte = *strp++;
01440        first_byte = *strp++;
01441       } else {
01442        first_byte = *strp++;
01443        second_byte = *strp++;
01444       }
01445       FrameMgrPutToken(fm, first_byte);
01446       FrameMgrPutToken(fm, second_byte);
01447       if (draw->title != NULL) {
01448        IMFeedbackList *fbl = &(draw->title->feedback[i]);
01449        for (j = 0; j < fbl->count_feedbacks; j++){
01450          IMFeedback *fb = &(fbl->feedbacks[j]);
01451          FrameMgrPutToken(fm, fb->type);
01452          FrameMgrPutToken(fm, fb->value);
01453        }
01454       }
01455     }
01456     int annotation_len = 0;
01457     FrameMgrPutToken(fm, annotation_len); /* annotation_len = 0 */
01458   }
01459   send_message(IM_LOOKUP_DRAW, reply, total_size);
01460   /* free FrameMgr */
01461   FrameMgrFree(fm);
01462 #endif /* USE_FRAMEMGR_ALWAYS */
01463 
01464   return True;
01465 }
01466 
01467 int IIIMPClient::lookup_process(IMLookupCBStruct *lookup_CB) {
01468 #if !defined(USE_FRAMEMGR_ALWAYS)
01469   char data[4 + 2 + 2 + 2 + 2];
01470   char *ptr;
01471 #else /* USE_FRAMEMGR_ALWAYS */
01472   FrameMgr fm;
01473   extern XimFrameRec im_lookup_process_fr[];
01474 #endif /* USE_FRAMEMGR_ALWAYS */
01475   IMLookupProcessCallbackStruct *process =
01476     (IMLookupProcessCallbackStruct *)&lookup_CB->lookup->todo.process;
01477 
01478 #if !defined(USE_FRAMEMGR_ALWAYS)
01479   ptr = (data + 4);
01480   if (False == need_swap) {
01481     req_put16(ptr, im_id);
01482     req_put16(ptr, lookup_CB->icid);
01483     req_put16(ptr, process->type);
01484     if (LookupIndex == process->type) {
01485       req_put16(ptr, process->value.index_of_choice_selected);
01486     } else {
01487       req_put16(ptr, process->value.page_operation_id);
01488     }
01489   } else {
01490     req_put16s(ptr, im_id);
01491     req_put16s(ptr, lookup_CB->icid);
01492     req_put16s(ptr, process->type);
01493     if (LookupIndex == process->type) {
01494       req_put16s(ptr, process->value.index_of_choice_selected);
01495     } else {
01496       req_put16s(ptr, process->value.page_operation_id);
01497     }
01498   }
01499   send_message(IM_LOOKUP_PROCESS, data, (sizeof (data)));
01500 #else /* USE_FRAMEMGR_ALWAYS */
01501   /* create FrameMgr */
01502   fm = FrameMgrInit(im_lookup_process_fr, NULL, need_swap);
01503 
01504   const int total_size = FrameMgrGetTotalSize(fm);
01505   CompoundString reply = CompoundString(total_size);
01506   memset(reply, 0, total_size);
01507   FrameMgrSetBuffer(fm, reply);
01508 
01509   FrameMgrPutToken(fm, im_id);
01510   FrameMgrPutToken(fm, lookup_CB->icid);
01511   FrameMgrPutToken(fm, process->type);
01512   if (process->type == LookupIndex)
01513     FrameMgrPutToken(fm, process->value.index_of_choice_selected);
01514   else
01515     FrameMgrPutToken(fm, process->value.page_operation_id);
01516   send_message(IM_LOOKUP_PROCESS, reply, total_size);
01517 
01518   /* free FrameMgr */
01519   FrameMgrFree(fm);
01520 #endif /* USE_FRAMEMGR_ALWAYS */
01521 
01522   return True;
01523 }
01524 
01525 int IIIMPClient::lookup_done(IMLookupCBStruct *lookup_CB) {
01526 #if !defined(USE_FRAMEMGR_ALWAYS)
01527   send_message(im_id, lookup_CB->icid, IM_LOOKUP_DONE);
01528 #else /* USE_FRAMEMGR_ALWAYS */
01529   extern XimFrameRec im_lookup_done_fr[];
01530   send_message(im_id, lookup_CB->icid,
01531               im_lookup_done_fr, IM_LOOKUP_DONE);
01532 #endif /* USE_FRAMEMGR_ALWAYS */
01533   return True;
01534 }
01535 
01536 int IIIMPClient::preedit_state(IMConvStateCBStruct *state_CB) {
01537 #if !defined(USE_FRAMEMGR_ALWAYS)
01538   char data[4 + 2 + 2 + 2 + 2];
01539   char *ptr;
01540 #else /* USE_FRAMEMGR_ALWAYS */
01541   FrameMgr fm;
01542   extern XimFrameRec im_trigger_notify_fr[];
01543 #endif /* USE_FRAMEMGR_ALWAYS */
01544 
01545 #if !defined(USE_FRAMEMGR_ALWAYS)
01546   ptr = (data + 4);
01547   if (False == need_swap) {
01548     req_put16(ptr, im_id);
01549     req_put16(ptr, state_CB->icid);
01550     req_put16(ptr, state_CB->conv_state);
01551     req_put16(ptr, 0);
01552   } else {
01553     req_put16s(ptr, im_id);
01554     req_put16s(ptr, state_CB->icid);
01555     req_put16s(ptr, state_CB->conv_state);
01556     req_put16s(ptr, 0);
01557   }
01558   send_message(IM_TRIGGER_NOTIFY, data, (sizeof (data)));
01559 #else /* USE_FRAMEMGR_ALWAYS */
01560   /* create FrameMgr */
01561   fm = FrameMgrInit(im_trigger_notify_fr, (char *)NULL, need_swap);
01562 
01563   const int total_size = FrameMgrGetTotalSize(fm);
01564   CompoundString reply = CompoundString(total_size);
01565   memset(reply, 0, total_size);
01566   FrameMgrSetBuffer(fm, reply);
01567 
01568   FrameMgrPutToken(fm, im_id);
01569   FrameMgrPutToken(fm, state_CB->icid);
01570   FrameMgrPutToken(fm, state_CB->conv_state);  // #0::ON #1::OFF
01571 
01572   send_message(IM_TRIGGER_NOTIFY, reply, total_size);
01573   /* free FrameMgr */
01574   FrameMgrFree(fm);
01575 #endif /* USE_FRAMEMGR_ALWAYS */
01576   return True;
01577 }
01578 
01579 int IIIMPClient::auxiliary_start(IMAuxCBStruct *auxiliary_CB) {
01580 #if !defined(USE_FRAMEMGR_ALWAYS)
01581   char *data;
01582   char *ptr;
01583   int total_size;
01584 #else /* USE_FRAMEMGR_ALWAYS */
01585   FrameMgr fm;
01586   extern XimFrameRec im_aux_start_fr[];
01587 #endif /* USE_FRAMEMGR_ALWAYS */
01588   IMAuxStartCallbackStruct *call_data =
01589     (IMAuxStartCallbackStruct*)&auxiliary_CB->aux->todo.start;
01590   char *enginename = call_data->aux_name;
01591   int i;
01592 
01593   if (!enginename) return True;    // nothing to do
01594 
01595 #if !defined(USE_FRAMEMGR_ALWAYS)
01596   total_size = 4;
01597   total_size += (2 + 2);
01598   total_size += 4;
01599   total_size += ascii_string_size(enginename);
01600   data = new char[total_size];
01601   ptr = (data + 4);
01602   if (False == need_swap) {
01603     req_put16(ptr, im_id);
01604     req_put16(ptr, auxiliary_CB->icid);
01605     req_put32(ptr, call_data->aux_index);
01606     ptr = req_put_ascii_string(ptr, enginename);
01607   } else {
01608     req_put16s(ptr, im_id);
01609     req_put16s(ptr, auxiliary_CB->icid);
01610     req_put32s(ptr, call_data->aux_index);
01611     ptr = req_put_ascii_string_s(ptr, enginename);
01612   }
01613   send_message(IM_AUX_START, data, total_size);
01614   delete [] data;
01615 #else /* USE_FRAMEMGR_ALWAYS */
01616   /* create FrameMgr */
01617   fm = FrameMgrInit(im_aux_start_fr, (char*)NULL, need_swap);
01618 
01619   /* set iteration count of engine name */
01620   int byte_length = strlen(enginename);
01621   FrameMgrSetIterCount(fm, byte_length);
01622 
01623   const int total_size = FrameMgrGetTotalSize(fm);
01624   CompoundString reply = CompoundString(total_size);
01625   memset(reply, 0, total_size);
01626   FrameMgrSetBuffer(fm, reply);
01627 
01628   FrameMgrPutToken(fm, im_id);
01629   FrameMgrPutToken(fm, auxiliary_CB->icid); 
01630   FrameMgrPutToken(fm, call_data->aux_index);
01631 
01632   if (need_swap == True) {
01633     for (i = 0; i < byte_length; i++) {
01634       CARD16 c = (CARD16)enginename[i];
01635       CARD8 byte_data;
01636       byte_data = *((CARD8 *)(&c) + 1);
01637       FrameMgrPutToken(fm, byte_data);
01638       byte_data = *((CARD8 *)(&c) + 0);
01639       FrameMgrPutToken(fm, byte_data);
01640     }
01641   } else {
01642     for (i = 0; i < byte_length; i++) {
01643       CARD16 c = (CARD16)enginename[i];
01644       CARD8 byte_data;
01645       byte_data = *((CARD8 *)(&c) + 0);
01646       FrameMgrPutToken(fm, byte_data);
01647       byte_data = *((CARD8 *)(&c) + 1);
01648       FrameMgrPutToken(fm, byte_data);
01649     }
01650   }
01651 
01652   send_message(IM_AUX_START, reply, total_size);
01653 
01654   /* free FrameMgr */
01655   FrameMgrFree(fm);
01656 #endif /* USE_FRAMEMGR_ALWAYS */
01657   return True;
01658 }
01659 
01660 int IIIMPClient::auxiliary_draw(IMAuxCBStruct *auxiliary_CB) {
01661 #if !defined(USE_FRAMEMGR_ALWAYS)
01662   char *data;
01663   char *ptr;
01664   int total_size;
01665   int string_list_size;
01666   IMText *string_values;
01667 #else /* USE_FRAMEMGR_ALWAYS */
01668   FrameMgr fm;
01669   extern XimFrameRec im_aux_draw_fr[];
01670 #endif /* USE_FRAMEMGR_ALWAYS */
01671   IMAuxDrawCallbackStruct *call_data =
01672     (IMAuxDrawCallbackStruct*)&auxiliary_CB->aux->todo.draw;
01673   char *enginename = call_data->aux_name;
01674   int i;
01675 
01676   if (!enginename) return True;    // nothing to do
01677 
01678 #if !defined(USE_FRAMEMGR_ALWAYS)
01679   total_size = 4;
01680   total_size += (2 + 2);
01681   total_size += 4;
01682   total_size += ascii_string_size(enginename);
01683   total_size += 4;   /* byte length of integer value list */
01684   total_size += (4 * call_data->count_integer_values);
01685                      /* integer value list */
01686   total_size += 4;   /* byte length of string value list */
01687   string_list_size = 0;
01688   for (i = 0; i < call_data->count_string_values; i++) {
01689     string_list_size +=
01690            utf16_string_size(call_data->string_values[i].char_length);
01691   }
01692   total_size += string_list_size;
01693   data = new char[total_size];
01694   ptr = (data + 4);
01695   string_values = call_data->string_values;
01696 
01697   if (False == need_swap) {
01698     req_put16(ptr, im_id);
01699     req_put16(ptr, auxiliary_CB->icid);
01700     req_put32(ptr, call_data->aux_index);
01701     ptr = req_put_ascii_string(ptr, enginename);
01702     req_put32(ptr, (4 * call_data->count_integer_values));
01703     for (i = 0; i < call_data->count_integer_values; i++) {
01704       req_put32(ptr, *(call_data->integer_values + i));
01705     }
01706     req_put32(ptr, string_list_size);
01707     for (i = 0; i < call_data->count_string_values; i++, string_values++) {
01708       ptr = req_put_utf16_string(ptr,
01709                              string_values->text.utf_chars,
01710                              string_values->char_length);
01711     }
01712   } else {
01713     req_put16s(ptr, im_id);
01714     req_put16s(ptr, auxiliary_CB->icid);
01715     req_put32s(ptr, call_data->aux_index);
01716     ptr = req_put_ascii_string_s(ptr, enginename);
01717     req_put32s(ptr, (4 * call_data->count_integer_values));
01718     for (i = 0; i < call_data->count_integer_values; i++) {
01719       req_put32s(ptr, *(call_data->integer_values + i));
01720     }
01721     req_put32s(ptr, string_list_size);
01722     for (i = 0; i < call_data->count_string_values; i++, string_values++) {
01723       ptr = req_put_utf16_string_s(ptr,
01724                                string_values->text.utf_chars, 
01725                                string_values->char_length);
01726     }
01727   }
01728 
01729   send_message(IM_AUX_DRAW, data, total_size);
01730   delete [] data;
01731   return True;
01732 
01733 #else /* USE_FRAMEMGR_ALWAYS */
01734   /* without FrameMgr */
01735   int total_length;
01736   int string_length;
01737   int enginename_length;
01738   IMText *    string_values;
01739   char *      uc;
01740   int         j;
01741 
01742   total_length = 2 + 2; /* im_id + ic_id */
01743   total_length += 4; /* aux_index */
01744   total_length += 2; /* length of engine name */
01745   enginename_length = strlen(enginename);
01746   total_length += (enginename_length * 2);
01747   if (0 == (enginename_length % 2)) {
01748     total_length += 2; /* padding */
01749   }
01750   total_length += 4; /* byte length of integer value list */
01751   total_length += (4 * call_data->count_integer_values);
01752                                    /* integer value list */
01753   total_length += 4; /* byte length of string value list */
01754   string_length = 0;
01755   for (i = 0; i < call_data->count_string_values; i++) {
01756     /* string value */
01757     string_length += (call_data->string_values[i].char_length * 2) + 2;
01758     if (0 == (call_data->string_values[i].char_length % 2)) {
01759       string_length += 2; /* padding */
01760     }
01761   }
01762   total_length += string_length;
01763 
01764   CompoundString request = CompoundString(total_length, 0);
01765   unsigned char * p;
01766 
01767   p = request.toUchar();
01768 
01769   if (False == need_swap) {
01770     *((CARD16 *)(p + 0)) = im_id;
01771     *((CARD16 *)(p + 2)) = auxiliary_CB->icid;
01772     *((CARD32 *)(p + 4)) = call_data->aux_index;
01773     *((CARD16 *)(p + 8)) = (enginename_length * 2);
01774 
01775     p += 10;
01776 
01777     for (i = 0; i < enginename_length; i++) {
01778       CARD16 c;
01779       c = (CARD16)(*(enginename + i));
01780       *((CARD16 *)p) = c;
01781       p += 2;
01782     }
01783     if (0 == (enginename_length % 2)) {
01784       *((CARD16 *)p) = 0;
01785       p += 2;
01786     }
01787 
01788     *((CARD32 *)p) = (4 * call_data->count_integer_values);
01789     p += 4;
01790     for (i = 0; i < call_data->count_integer_values; i++) {
01791       *((CARD32 *)p) = *(call_data->integer_values + i);
01792       p += 4;
01793     }
01794 
01795     *((CARD32 *)p) = string_length;
01796     p += 4;
01797 
01798     string_values = call_data->string_values;
01799     for (i = 0; i < call_data->count_string_values; i++) {
01800       uc = (char *)((string_values + i)->text.utf_chars);
01801       *((CARD16 *)p) = ((string_values + i)->char_length * 2);
01802       p += 2;
01803       for (j = 0; j < (string_values + i)->char_length; j++) {
01804        *(p++) = *(uc++);
01805        *(p++) = *(uc++);
01806       }
01807       if (0 == ((string_values + i)->char_length % 2)) {
01808        *(p++) = 0;
01809        *(p++) = 0;
01810       }
01811     }
01812   } else {
01813     *((CARD16 *)(p + 0)) = req_swap16(im_id);
01814     *((CARD16 *)(p + 2)) = req_swap16(auxiliary_CB->icid);
01815     *((CARD32 *)(p + 4)) = req_swap32(call_data->aux_index);
01816     *((CARD16 *)(p + 8)) = req_swap16(enginename_length * 2);
01817 
01818     p += 10;
01819 
01820     for (i = 0; i < enginename_length; i++) {
01821       CARD16 c;
01822       c = (CARD16)(*(enginename + i));
01823       *((CARD16 *)p) = req_swap16(c);
01824       p += 2;
01825     }
01826     if (0 == (enginename_length % 2)) {
01827       *((CARD16 *)p) = 0;
01828       p += 2;
01829     }
01830 
01831     *((CARD32 *)p) = req_swap32(4 * call_data->count_integer_values);
01832     p += 4;
01833     for (i = 0; i < call_data->count_integer_values; i++) {
01834       *((CARD32 *)p) = req_swap32(*(call_data->integer_values + i));
01835       p += 4;
01836     }
01837 
01838     *((CARD32 *)p) = req_swap32(string_length);
01839     p += 4;
01840 
01841     string_values = call_data->string_values;
01842     for (i = 0; i < call_data->count_string_values; i++) {
01843       uc = (char *)((string_values + i)->text.utf_chars);
01844       *((CARD16 *)p) = req_swap16((string_values + i)->char_length * 2);
01845       p += 2;
01846       for (j = 0; j < (string_values + i)->char_length; j++) {
01847        *(p++) = *(uc + 1);
01848        *(p++) = *(uc + 0);
01849        uc += 2;
01850       }
01851       if (0 == ((string_values + i)->char_length % 2)) {
01852        *(p++) = 0;
01853        *(p++) = 0;
01854       }
01855     }
01856   }
01857 
01858   send_message(IM_AUX_DRAW, request, total_length);
01859   return True;
01860 
01861 #if 0
01862   /* create FrameMgr */
01863   fm = FrameMgrInit(im_aux_draw_fr, (char*)NULL, need_swap);
01864 
01865   /* set iteration count of engine name */
01866   int byte_length = strlen(enginename);
01867   FrameMgrSetIterCount(fm, byte_length);
01868 
01869   /* set iteration count of integer list */
01870   FrameMgrSetIterCount(fm, call_data->count_integer_values);
01871 
01872   /* set iteration count of string list */
01873   FrameMgrSetIterCount(fm, call_data->count_string_values);
01874 
01875   for (i = 0; i < call_data->count_string_values; i++) {
01876     FrameMgrSetIterCount(fm, call_data->string_values[i].char_length);
01877   }
01878 
01879   const int total_size = FrameMgrGetTotalSize(fm);
01880   CompoundString reply = CompoundString(total_size);
01881   memset(reply, 0, total_size);
01882   FrameMgrSetBuffer(fm, reply);
01883 
01884   FrameMgrPutToken(fm, im_id);
01885   FrameMgrPutToken(fm, auxiliary_CB->icid); 
01886   FrameMgrPutToken(fm, call_data->aux_index);
01887 
01888   if (need_swap == True) {
01889     for (i = 0; i < byte_length; i++) {
01890       CARD16 c = (CARD16)enginename[i];
01891       CARD8 byte_data;
01892       byte_data = *((CARD8 *)(&c) + 1);
01893       FrameMgrPutToken(fm, byte_data);
01894       byte_data = *((CARD8 *)(&c) + 0);
01895       FrameMgrPutToken(fm, byte_data);
01896     }
01897   } else {
01898     for (i = 0; i < byte_length; i++) {
01899       CARD16 c = (CARD16)enginename[i];
01900       CARD8 byte_data;
01901       byte_data = *((CARD8 *)(&c) + 0);
01902       FrameMgrPutToken(fm, byte_data);
01903       byte_data = *((CARD8 *)(&c) + 1);
01904       FrameMgrPutToken(fm, byte_data);
01905     }
01906   }
01907 
01908   for (i = 0; i < call_data->count_integer_values; i++) {
01909     FrameMgrPutToken(fm, call_data->integer_values[i]);
01910   }
01911 
01912   UTFCHAR *utf_chars;
01913   int text_length;
01914   for (i = 0; i < call_data->count_string_values; i++) {
01915     text_length = call_data->string_values[i].char_length;
01916 
01917     if (call_data->string_values[i].encoding == UTF16_CODESET) {
01918       utf_chars = call_data->string_values[i].text.utf_chars;
01919     } else {
01920       utf_chars = 0;
01921     }
01922     SetStringToFrame(fm, utf_chars, text_length);
01923   }
01924   send_message(IM_AUX_DRAW, reply, total_size);
01925 
01926   /* free FrameMgr */
01927   FrameMgrFree(fm);
01928   return True;
01929 #endif
01930 #endif /* USE_FRAMEMGR_ALWAYS */
01931 }
01932 
01933 int IIIMPClient::auxiliary_done(IMAuxCBStruct *auxiliary_CB) {
01934 #if !defined(USE_FRAMEMGR_ALWAYS)
01935   char *data;
01936   char *ptr;
01937   int total_size;
01938 #else /* USE_FRAMEMGR_ALWAYS */
01939   FrameMgr fm;
01940   extern XimFrameRec im_aux_done_fr[];
01941 #endif /* USE_FRAMEMGR_ALWAYS */
01942   IMAuxDoneCallbackStruct *call_data =
01943     (IMAuxDoneCallbackStruct*)&auxiliary_CB->aux->todo.done;
01944   char *enginename = call_data->aux_name;
01945   int i;
01946 
01947   if (!enginename) return True;    // nothing to do
01948 
01949 #if !defined(USE_FRAMEMGR_ALWAYS)
01950   total_size = 4;
01951   total_size += (2 + 2);
01952   total_size += 4;
01953   total_size += ascii_string_size(enginename);
01954   data = new char[total_size];
01955   ptr = (data + 4);
01956   if (False == need_swap) {
01957     req_put16(ptr, im_id);
01958     req_put16(ptr, auxiliary_CB->icid);
01959     req_put32(ptr, call_data->aux_index);
01960     ptr = req_put_ascii_string(ptr, enginename);
01961   } else {
01962     req_put16s(ptr, im_id);
01963     req_put16s(ptr, auxiliary_CB->icid);
01964     req_put32s(ptr, call_data->aux_index);
01965     ptr = req_put_ascii_string_s(ptr, enginename);
01966   }
01967   send_message(IM_AUX_DONE, data, total_size);
01968   delete [] data;
01969 #else /* USE_FRAMEMGR_ALWAYS */
01970   /* create FrameMgr */
01971   fm = FrameMgrInit(im_aux_done_fr, (char*)NULL, need_swap);
01972 
01973   /* set iteration count of engine name */
01974   int byte_length = strlen(enginename);
01975   FrameMgrSetIterCount(fm, byte_length);
01976 
01977   const int total_size = FrameMgrGetTotalSize(fm);
01978   CompoundString reply = CompoundString(total_size);
01979   memset(reply, 0, total_size);
01980   FrameMgrSetBuffer(fm, reply);
01981 
01982   FrameMgrPutToken(fm, im_id);
01983   FrameMgrPutToken(fm, auxiliary_CB->icid); 
01984   FrameMgrPutToken(fm, call_data->aux_index);
01985 
01986   if (need_swap == True) {
01987     for (i = 0; i < byte_length; i++) {
01988       CARD16 c = (CARD16)enginename[i];
01989       CARD8 byte_data;
01990       byte_data = *((CARD8 *)(&c) + 1);
01991       FrameMgrPutToken(fm, byte_data);
01992       byte_data = *((CARD8 *)(&c) + 0);
01993       FrameMgrPutToken(fm, byte_data);
01994     }
01995   } else {
01996     for (i = 0; i < byte_length; i++) {
01997       CARD16 c = (CARD16)enginename[i];
01998       CARD8 byte_data;
01999       byte_data = *((CARD8 *)(&c) + 0);
02000       FrameMgrPutToken(fm, byte_data);
02001       byte_data = *((CARD8 *)(&c) + 1);
02002       FrameMgrPutToken(fm, byte_data);
02003     }
02004   }
02005 
02006   send_message(IM_AUX_DONE, reply, total_size);
02007 
02008   /* free FrameMgr */
02009   FrameMgrFree(fm);
02010 #endif /* USE_FRAMEMGR_ALWAYS */
02011   return True;
02012 }
02013 
02014 int IIIMPClient::conversion_start(IMConvStateCBStruct *state_CB) {
02015   return preedit_state(state_CB);
02016   return 0;
02017 }
02018 
02019 int IIIMPClient::conversion_end(IMConvStateCBStruct *state_CB) {
02020   return preedit_state(state_CB);
02021   return 0;
02022 }