Back to index

im-sdk  12.3.91
sampleja.c
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 #ifdef WIN32
00043 #include <windows.h>
00044 #endif
00045 
00046 #include <stdio.h>
00047 #include <stdlib.h>
00048 #include <string.h>
00049 #include <sys/types.h>
00050 
00051 #include "SunIM.h"
00052 
00053 Bool if_sampleja_OpenIF(iml_if_t *);
00054 Bool if_sampleja_CloseIF(iml_if_t *);
00055 Bool if_sampleja_GetIFValue(iml_if_t *, IMArgList, int);
00056 Bool if_sampleja_SetIFValue(iml_if_t *, IMArgList, int);
00057 Bool if_sampleja_OpenDesktop(iml_desktop_t *, IMArgList, int);
00058 Bool if_sampleja_CloseDesktop(iml_desktop_t *);
00059 Bool if_sampleja_CreateSC(iml_session_t *, IMArgList, int);
00060 Bool if_sampleja_DestroySC(iml_session_t *);
00061 Bool if_sampleja_GetSCValue(iml_session_t *, IMArgList, int);
00062 Bool if_sampleja_SetSCValue(iml_session_t *, IMArgList, int);
00063 IMText *if_sampleja_ResetSC(iml_session_t *);
00064 void if_sampleja_SetSCFocus(iml_session_t *);
00065 void if_sampleja_UnsetSCFocus(iml_session_t *);
00066 void if_sampleja_SendEvent(iml_session_t *, IMInputEvent * ev);
00067 
00068 /* IF Method */
00069 if_methods_t sampleja_methods2 = {
00070     if_sampleja_OpenIF,
00071     if_sampleja_CloseIF,
00072     if_sampleja_GetIFValue,
00073     if_sampleja_SetIFValue,
00074     if_sampleja_OpenDesktop,
00075     if_sampleja_CloseDesktop,
00076     if_sampleja_CreateSC,
00077     if_sampleja_DestroySC,
00078     if_sampleja_GetSCValue,
00079     if_sampleja_SetSCValue,
00080     if_sampleja_ResetSC,
00081     if_sampleja_SetSCFocus,
00082     if_sampleja_UnsetSCFocus,
00083     if_sampleja_SendEvent
00084 };
00085 
00086 UTFCHAR lename_string[] = {0x30b5, 0x30f3, 0x30d7, 0x30eb, 0x65e5, 0x672c, 0x8a9e, 0x30a8, 0x30f3, 0x30b8, 0x30f3, 0x0};
00087 UTFCHAR jahrn_string[] = {0x65e5, 0x672c, 0x8a9e, 0x0};
00088 
00089 static IMLEName lename = {
00090     "sampleja", lename_string      /* LE id, HRN */
00091 };
00092 
00093 static IMLocale locales[] = {
00094     {"ja", jahrn_string},   /* locale id, HRN */
00095     NULL
00096 };
00097 
00098 IMObjectDescriptorStruct *objects = NULL;
00099 
00100 void init_objects();
00101 
00102 #ifdef WIN32
00103 #define EXPORT extern __declspec(dllexport)
00104 
00105 EXPORT
00106 
00107 #endif
00108 
00109 void
00110 if_GetIfInfo(
00111     IMArgList args,
00112     int num_args
00113 )
00114 {
00115     int i;
00116     init_objects();
00117     for (i = 0; i < num_args; i++, args++) {
00118         switch (args->id) {
00119             case IF_VERSION:
00120                 args->value = (IMArgVal) "1.2";
00121                 break;
00122             case IF_METHOD_TABLE:
00123                 args->value = (IMArgVal) & sampleja_methods2;
00124                 break;
00125             case IF_LE_NAME:
00126                 args->value = (IMArgVal) & lename;
00127                 break;
00128             case IF_SUPPORTED_LOCALES:
00129                 args->value = (IMArgVal) & locales;
00130                 break;
00131             case IF_SUPPORTED_OBJECTS:
00132                 args->value = (IMArgVal) objects;
00133                 break;
00134             case IF_NEED_THREAD_LOCK:
00135                 args->value = (IMArgVal) False;
00136                 break;
00137             default:
00138                 break;
00139             }
00140     }
00141 }
00142 
00143 Bool receive_keylist(iml_session_t *, IMKeyListEvent *);
00144 void preedit_test(iml_session_t *);
00145 void lookup_test(iml_session_t *);
00146 
00147 #ifdef test
00148 char *class_names[] = {
00149     "wnn_aux_sample",
00150     "wnn_aux_sample",
00151 };
00152 #else
00153 char *class_names[] = {
00154     "com.sun.iiim.sample.sampleja.SamplePanel",
00155     "com.sun.iiim.sample.sampleja.SampleAux"
00156 };
00157 #endif
00158 
00159 enum {
00160     SAMPLE_AUX_PANEL = 0,
00161     SAMPLE_AUX_DICT = 1
00162 };
00163 
00164 #define       MAX_AUX       2
00165 
00166 void aux_start(iml_session_t *, int);
00167 void aux_draw(iml_session_t *, int, int, int *, int, UTFCHAR **);
00168 void aux_done(iml_session_t *, int);
00169 void receive_aux(iml_session_t *, IMAuxDrawCallbackStruct *);
00170 
00171 void my_conversion_on(iml_session_t *);
00172 void my_conversion_off(iml_session_t *);
00173 
00174 void status_draw(iml_session_t *);
00175 void preedit_draw(iml_session_t *);
00176 void preedit_draw_reverse(iml_session_t *);
00177 void shrink_preedit(iml_session_t *);
00178 void expand_preedit(iml_session_t *);
00179 void caret_move_left(iml_session_t *);
00180 void caret_move_right(iml_session_t *);
00181 void caret_move_home(iml_session_t *);
00182 void caret_move_end(iml_session_t *);
00183 void commit(iml_session_t *);
00184 void commit_onechar(iml_session_t *, int);
00185 void commit_partial(iml_session_t *);
00186 void luc_draw(iml_session_t *);
00187 
00188 void lookup_next(iml_session_t *);
00189 void lookup_prev(iml_session_t *);
00190 
00191 void lookup_commit(iml_session_t *, int);
00192 
00193 void list_test(iml_session_t *);
00194 
00195 void to_kana(iml_session_t *);
00196 void to_hira(iml_session_t *);
00197 
00198 IMText *make_preedit_imtext(iml_session_t *);
00199 IMText *make_imtext(iml_session_t *, UTFCHAR *);
00200 
00201 Bool do_convert(iml_session_t *);
00202 
00203 void free_objects();
00204 
00205 int UTFCHARLen(UTFCHAR *);
00206 int UTFCHARCpy(UTFCHAR *, UTFCHAR *);
00207 Bool UTFCHARCmp2(UTFCHAR *, char *, int);
00208 Bool UTFCHARCmp(UTFCHAR *, UTFCHAR *);
00209 
00210 void preedit_buf_print(iml_session_t *);
00211 
00212 void iml_make_preedit_draw_with_chgpos_inst_test(iml_session_t *);
00213 
00214 IMFeedbackList *create_feedback(iml_session_t * s, int size);
00215 IMFeedbackList *create_feedback2(iml_session_t * s, int size);
00216 IMFeedbackList *create_feedback_with_color(iml_session_t * s, int size, int feedback, int fg, int bg);
00217 void set_feedback_private(IMFeedbackList *, int, int, int, int);
00218 void set_feedback(IMFeedbackList *, int);
00219 int get_feedback(IMFeedbackList *);
00220 
00221 
00222 typedef struct henkan_table3_ {
00223     UTFCHAR *from;
00224     UTFCHAR *to;
00225 }   henkan_table3;
00226 
00227 /* data per desktop */
00228 typedef struct {
00229     iml_session_t *auxproxy_session;
00230     int aux_start[3];
00231     int wordcount;
00232     henkan_table3 *userdict[100];
00233 }   MyDataPerDesktop;
00234 
00235 /* data per session */
00236 typedef struct {
00237     int status_start;
00238     int preedit_start;
00239     int luc_start;
00240     int conv_on;
00241     
00242     IMText **luc_candidates;
00243     IMText **luc_labels;
00244     
00245     UTFCHAR *conversion_string;    /* reversed */
00246     UTFCHAR *preedit_string;       /* underlined */
00247     
00248     int luc_top;
00249     int luc_nchoices;
00250     int luc_current_candidate;     /* index of current candidate */
00251     int luc_type;           /* Clinet or IM Master */
00252     int max_candidates;
00253     
00254     UTFCHAR *preedit_buf;   /* preedit */
00255     IMFeedbackList *preedit_feedback;     /* feedback for preedit */
00256     int caret_pos;
00257     
00258     IMFeedbackList *luc_fbs_reverse;
00259     IMFeedbackList *luc_fbs_normal;
00260 }   MyDataPerSession;
00261 
00262 void add_dict(MyDataPerDesktop *, UTFCHAR *, UTFCHAR *);
00263 
00264 #define       DEBUG
00265 
00266 Bool
00267 if_sampleja_OpenIF(
00268     iml_if_t * If
00269 )
00270 {
00271 #ifdef DEBUG
00272     printf("if_sampleja_OpenIF()\n");
00273     printf("  If=[%x]\n", If);
00274     printf("  locale=[%s]\n", If->locale);
00275     printf("  if_name=[%s]\n", If->if_name);
00276 #endif
00277     init_objects();
00278     return True;
00279 }
00280 
00281 Bool
00282 if_sampleja_CloseIF(
00283     iml_if_t * If
00284 )
00285 {
00286 #ifdef DEBUG
00287     printf("if_sampleja_CloseIF()\n");
00288     printf("  If=[%x]\n", If);
00289     printf("  locale=[%s]\n", If->locale);
00290     printf("  if_name=[%s]\n", If->if_name);
00291 #endif
00292     
00293 #ifdef notdef
00294     free_objects();
00295 #endif
00296     return True;
00297 }
00298 
00299 UTFCHAR aux_name_panel[] = {0x30b5, 0x30f3, 0x30d7, 0x30eb, 0xff21, 0xff35, 0xff38, '-', 0x30d1, 0x30cd, 0x30eb, 0};
00300 UTFCHAR aux_name_aux[] = {0x30b5, 0x30f3, 0x30d7, 0x30eb, 0xff21, 0xff35, 0xff38, '-', 0xff21, 0xff35, 0xff38, 0};
00301 
00302 void
00303 free_objects()
00304 {
00305     IMObjectDescriptorStruct *l = objects;
00306     
00307     while (l->leid) {
00308         free(l->name);
00309         l++;
00310     };
00311     
00312     free(objects);
00313     
00314     objects = NULL;
00315 }
00316 
00317 void
00318 init_objects()
00319 {
00320     IMObjectDescriptorStruct *l;
00321     objects = (IMObjectDescriptorStruct *) calloc(3, sizeof(IMObjectDescriptorStruct));
00322     l = objects;
00323     
00324     l->leid = "sampleja";                 /* engine id */
00325     l->type = IM_DOWNLOADINGOBJECT_JARGUI_TYPE;  /* object type */
00326     l->name = aux_name_panel;                    /* HRN */
00327     l->name_length = 11;                  /* len of HRN */
00328     l->domain = "com.sun";                /* reversed domain */
00329     l->scope = "sampleja";                /* only for sampleja */
00330 
00331 #ifdef WIN32
00332     l->path = "d:\\sampleja_obj.jar";            /* path */
00333 #else
00334     l->path = "/usr/lib/iiim/le/sampleja/sampleja_obj.jar";    /* path */
00335 #endif
00336     l->signature = "";
00337     l->class_names = class_names;
00338     l->count_names = 2;
00339 
00340     l++;
00341     l->leid = "sampleja";                 /* engine id */
00342     l->type = IM_DOWNLOADINGOBJECT_BINGUI_TYPE;  /* object type */
00343     l->name = aux_name_panel;                    /* HRN */
00344     l->name_length = 11;
00345     l->domain = "com.sun";
00346     l->scope = "sampleja";                /* only for sampleja */
00347     l->path = "sampleja/aux.so";   /* path for .so from /usr/lib/iiim/le/ */
00348                                           /* this will be
00349                                               /usr/lib/iiim/le/sampleja/aux.so
00350                                           */
00351     l->signature = "";
00352     l->basepath = NULL;            /* only for CCDEF */
00353     l->encoding = NULL;            /* only for CCDEF */
00354 }
00355 
00356 Bool
00357 if_sampleja_GetIFValue(
00358     iml_if_t * If,
00359     IMArgList args,
00360     int num_args
00361 )
00362 {
00363     int i;
00364 #ifdef DEBUG
00365     printf("if_sampleja_GetIFValue()\n");
00366     printf("  If=[%x]\n", If);
00367     printf("  locale=[%s]\n", If->locale);
00368     printf("  if_name=[%s]\n", If->if_name);
00369 #endif
00370     return True;
00371 }
00372 
00373 Bool
00374 if_sampleja_SetIFValue(
00375     iml_if_t * If,
00376     IMArgList args,
00377     int num_args
00378 )
00379 {
00380     int i;
00381 #ifdef DEBUG
00382     printf("if_sampleja_SetIFValue()\n");
00383     printf("  If=[%x]\n", If);
00384     printf("  locale=[%s]\n", If->locale);
00385     printf("  if_name=[%s]\n", If->if_name);
00386 #endif
00387     for (i = 0; i < num_args; i++, args++) {
00388         switch (args->id) {
00389         }
00390     }
00391     return True;
00392 }
00393 
00394 Bool
00395 if_sampleja_OpenDesktop(
00396     iml_desktop_t * desktop,
00397     IMArgList args,
00398     int num_args
00399 )
00400 {
00401     MyDataPerDesktop *desktop_data = (MyDataPerDesktop *) calloc(1, sizeof(MyDataPerDesktop));
00402     int i;
00403 #ifdef DEBUG
00404     printf("if_sampleja_OpenDesktop()\n");
00405     printf("  If=[%x]\n", desktop->If);
00406     printf("  desktop=[%x]\n", desktop);
00407     printf("  locale=[%s]\n", desktop->If->locale);
00408     printf("  if_name=[%s]\n", desktop->If->if_name);
00409     
00410     printf("  BASIC INFO - USER:%s\n", desktop->user_name);
00411     printf("  BASIC INFO - HOST:%s\n", desktop->host_name);
00412     printf("  BASIC INFO - DISPLAY:%s\n", desktop->display_id);
00413     
00414     for (i = 0; i < num_args; i++, args++) {
00415         switch (args->id) {
00416             case UI_USER_NAME:
00417                 if (args->value) {
00418                     printf("       UI_USER_NAME=%s\n", args->value);
00419                 }
00420                 break;
00421             case UI_HOST_NAME:
00422                 if (args->value) {
00423                     printf("       UI_HOST_NAME=%s\n", args->value);
00424                 }
00425                 break;
00426             case UI_DISPLAY_ID:
00427                 if (args->value) {
00428                     printf("       UI_DISPLAY_ID=%s\n", args->value);
00429                 }
00430                 break;
00431             case UI_PROTOCOL_TYPE:
00432                 if (args->value) {
00433                     printf("       UI_PROTOCOL_TYPE=%s\n", args->value);
00434                 }
00435                 break;
00436             case UI_CLIENT_TYPE:
00437                 if (args->value) {
00438                     printf("       UI_CLIENT_TYPE=%s\n", args->value);
00439                 }
00440                 break;
00441             case UI_XSERVER_VENDOR:
00442                 if (args->value) {
00443                     printf("       UI_XSERVER_VENDOR=%s\n", args->value);
00444                 }
00445                 break;
00446             case UI_OS_NAME:
00447                 if (args->value) {
00448                     printf("       UI_OS_NAME=%s\n", args->value);
00449                 }
00450                 break;
00451             case UI_OS_ARCH:
00452                 if (args->value) {
00453                     printf("       UI_OS_ARCH=%s\n", args->value);
00454                 }
00455                 break;
00456             case UI_OS_VERSION:
00457                 if (args->value) {
00458                     printf("       UI_OS_VERSION=%s\n", args->value);
00459                 }
00460                 break;
00461             case UI_AUTH_PASSWD:
00462                 if (args->value) {
00463                     printf("       UI_AUTH_PASSWD=%s\n", args->value);
00464                 }
00465                 break;
00466             }
00467     }
00468 #endif
00469     
00470     
00471     for (i = 0; i < MAX_AUX; i++) {
00472         desktop_data->aux_start[i] = False;
00473     }
00474     desktop_data->auxproxy_session = 0;
00475     desktop->specific_data = (void *) desktop_data;
00476     return True;
00477 }
00478 
00479 Bool
00480 if_sampleja_CloseDesktop(
00481     iml_desktop_t * desktop
00482 )
00483 {
00484     MyDataPerDesktop *desktop_data = (MyDataPerDesktop *) desktop->specific_data;
00485     int i;
00486 #ifdef DEBUG
00487     printf("if_sampleja_CloseDesktop()\n");
00488     printf("  If=[%x]\n", desktop->If);
00489     printf("  desktop=[%x]\n", desktop);
00490     printf("  locale=[%s]\n", desktop->If->locale);
00491     printf("  if_name=[%s]\n", desktop->If->if_name);
00492     printf("  USER:%s\n", desktop->user_name);
00493     printf("  HOST:%s\n", desktop->host_name);
00494     printf("  DISPLAY:%s\n", desktop->display_id);
00495 #endif
00496     for (i = 0; i < desktop_data->wordcount; i++) {
00497         henkan_table3 *p = desktop_data->userdict[i];
00498         free(p->from);
00499         free(p->to);
00500         free(p);
00501     }
00502     
00503     free(desktop_data);
00504     return True;
00505 }
00506 
00507 #define       BUFSIZE       256
00508 #define       MAXCANDIDATES 40
00509 
00510 Bool
00511 if_sampleja_CreateSC(
00512     iml_session_t * s,
00513     IMArgList args,
00514     int num_args
00515 )
00516 {
00517     iml_desktop_t *desktop = s->desktop;
00518     IMFeedbackList *fbl;
00519     IMFeedback *fb;
00520     int i;
00521     MyDataPerSession *p = (MyDataPerSession *) calloc(1, sizeof(MyDataPerSession));
00522     p->status_start = False;
00523     p->luc_start = False;
00524     p->preedit_start = False;
00525     p->preedit_buf = (UTFCHAR *) calloc(1, sizeof(UTFCHAR) * BUFSIZE);
00526     
00527     p->conversion_string = (UTFCHAR *) calloc(1, sizeof(UTFCHAR) * BUFSIZE);
00528     p->preedit_string = (UTFCHAR *) calloc(1, sizeof(UTFCHAR) * BUFSIZE);
00529     p->luc_candidates = NULL;
00530     p->luc_labels = NULL;
00531     p->luc_nchoices = 36;
00532     p->caret_pos = -1;
00533     p->max_candidates = MAXCANDIDATES - 1;
00534     p->luc_current_candidate = 0;
00535     
00536     p->preedit_feedback = create_feedback(0, BUFSIZE);
00537     p->luc_fbs_reverse = create_feedback(0, BUFSIZE);
00538     p->luc_fbs_normal = create_feedback(0, BUFSIZE);
00539     
00540     for (i = 0; i < BUFSIZE; i++) {
00541         set_feedback(&p->preedit_feedback[i], IMUnderline);
00542         set_feedback(&p->luc_fbs_reverse[i], IMReverse);
00543         set_feedback(&p->luc_fbs_normal[i], IMNormal);
00544     }
00545     
00546 #ifdef DEBUG
00547     printf("if_sampleja_CreateSC()\n");
00548     printf("  If=[%x]\n", desktop->If);
00549     printf("  desktop=[%x]\n", desktop);
00550     printf("  locale=[%s]\n", desktop->If->locale);
00551     printf("  if_name=[%s]\n", desktop->If->if_name);
00552     
00553     printf("  BASIC INFO - USER:%s\n", desktop->user_name);
00554     printf("  BASIC INFO - HOST:%s\n", desktop->host_name);
00555     printf("  BASIC INFO - DISPLAY:%s\n", desktop->display_id);
00556     
00557     for (i = 0; i < num_args; i++, args++) {
00558         switch (args->id) {
00559             case UI_USER_NAME:
00560                 if (args->value) {
00561                     printf("       UI_USER_NAME=%s\n", args->value);
00562                 }
00563                 break;
00564             case UI_HOST_NAME:
00565                 if (args->value) {
00566                     printf("       UI_HOST_NAME=%s\n", args->value);
00567                 }
00568                 break;
00569             case UI_DISPLAY_ID:
00570                 if (args->value) {
00571                     printf("       UI_DISPLAY_ID=%s\n", args->value);
00572                 }
00573                 break;
00574             case UI_PROTOCOL_TYPE:
00575                 if (args->value) {
00576                     printf("       UI_PROTOCOL_TYPE=%s\n", args->value);
00577                 }
00578                 break;
00579             case UI_XSERVER_VENDOR:
00580                 if (args->value) {
00581                     printf("       UI_XSERVER_VENDOR=%s\n", args->value);
00582                 }
00583                 break;
00584             case UI_CLIENT_TYPE:
00585                 if (args->value) {
00586                     printf("       UI_CLIENT_TYPE=%s\n", args->value);
00587                 }
00588                 break;
00589             case UI_OS_NAME:
00590                 if (args->value) {
00591                     printf("       UI_OS_NAME=%s\n", args->value);
00592                 }
00593                 break;
00594             case UI_OS_ARCH:
00595                 if (args->value) {
00596                     printf("       UI_OS_ARCH=%s\n", args->value);
00597                 }
00598                 break;
00599             case UI_OS_VERSION:
00600                 if (args->value) {
00601                     printf("       UI_OS_VERSION=%s\n", args->value);
00602                 }
00603             case UI_AUTH_PASSWD:
00604                 if (args->value) {
00605                     printf("       UI_AUTH_PASSWD=%s\n", args->value);
00606                 }
00607                 break;
00608             }
00609     }
00610 #endif
00611     
00612     s->specific_data = (void *) p;
00613     return True;
00614 }
00615 
00616 Bool
00617 if_sampleja_DestroySC(
00618     iml_session_t * s
00619 )
00620 {
00621     int i;
00622     MyDataPerSession *p = (MyDataPerSession *) s->specific_data;
00623     MyDataPerDesktop *desktop_data = (MyDataPerDesktop*) s->desktop->specific_data;
00624 
00625     iml_session_t *j = s->desktop->session_list;
00626     
00627     if (p->preedit_buf) {
00628         free((char *) p->preedit_buf);
00629     }
00630     if (p->conversion_string) {
00631         free((char *) p->conversion_string);
00632     }
00633     if (p->preedit_string) {
00634         free((char *) p->preedit_string);
00635     }
00636     if (p->preedit_feedback) {
00637         free((char *) p->preedit_feedback);
00638     }
00639     if (p->luc_fbs_reverse) {
00640         free((char *) p->luc_fbs_reverse);
00641     }
00642     if (p->luc_fbs_normal) {
00643         free((char *) p->luc_fbs_normal);
00644     }
00645     free((char *) p);
00646 
00647     if(desktop_data->auxproxy_session == s){
00648        printf("auxproxy_session is destroyed\n");
00649        desktop_data->auxproxy_session = 0;
00650     }
00651 
00652 #ifdef DEBUG
00653     printf("if_sampleja_DestroySC(s=%x)\n", s);
00654     printf("  s=[%x]\n", s);
00655     printf("  If=[%x]\n", s->desktop->If);
00656     printf("  desktop=[%x]\n", s->desktop);
00657     printf("  locale=[%s]\n", s->desktop->If->locale);
00658     printf("  if_name=[%s]\n", s->desktop->If->if_name);
00659     printf("  USER:%s\n", s->desktop->user_name);
00660     printf("  HOST:%s\n", s->desktop->host_name);
00661     
00662     i = 1;
00663     
00664     i = 1;
00665     printf("  == Remaining Sessions START ==\n");
00666     while (j) {
00667         if (j == s) {
00668         } else {
00669             printf("           session %d = %x\n", i, j);
00670         }
00671         
00672         
00673         if (j->next) {
00674             j = j->next;
00675         } else {
00676             break;
00677         }
00678         i++;
00679     }
00680     printf("  == Remaining Sessions END ==\n");
00681 #endif
00682     return True;
00683 }
00684 
00685 Bool
00686 if_sampleja_GetSCValue(
00687     iml_session_t * s,
00688     IMArgList args,
00689     int num_args
00690 )
00691 {
00692     int i;
00693     IMArg *p = args;
00694     
00695     static int charsubset[] = {
00696         67,                 /* LATIN */
00697         47,                 /* HIRAGANA */
00698         48,                 /* KATAKANA */
00699         71,                 /* KANJI */
00700         0
00701     };
00702     
00703 #ifdef DEBUG
00704     printf("if_sampleja_GetSCValue(s=%x)\n", s);
00705     printf("  s=[%x]\n", s);
00706     printf("  If=[%x]\n", s->desktop->If);
00707     printf("  desktop=[%x]\n", s->desktop);
00708     printf("  locale=[%s]\n", s->desktop->If->locale);
00709     printf("  if_name=[%s]\n", s->desktop->If->if_name);
00710     printf("  USER:%s\n", s->desktop->user_name);
00711     printf("  HOST:%s\n", s->desktop->host_name);
00712 #endif
00713     for (i = 0; i < num_args; i++, p++) {
00714         switch (p->id) {
00715             case SC_SUPPORTED_CHARACTER_SUBSETS:
00716                 /* specify CHARACTER_SUBSETS */
00717                 p->value = (IMArgVal) charsubset;
00718                 break;
00719             default:
00720                 break;
00721             }
00722     }
00723     return True;
00724 }
00725 
00726 UTFCHAR on_string[] = {0x65e5, 0x672c, 0x8a9e, 0x30aa, 0x30f3, 0};
00727 UTFCHAR off_string[] = {0x65e5, 0x672c, 0x8a9e, 0x30aa, 0x30d5, 0};
00728 UTFCHAR title_string[] = {0x9078, 0x629e, 0x30a6, 0x30a3, 0x30f3, 0x30c9, 0x30a6, 0};
00729 UTFCHAR candidate_string[] = {0x9078, 0x629e, 0x30a6, 0x30a3, 0x30f3, 0x30c9, 0x30a6, 0};
00730 UTFCHAR add_string[] = {0x8ffd,0x52a0,0x3057,0x307e,0x3057,0x305f,0x0};
00731 
00732 void
00733 my_conversion_on(
00734     iml_session_t * s
00735 )
00736 {
00737     iml_inst *lp;
00738     iml_inst *rrv = NULL;
00739     MyDataPerSession *session_data = (MyDataPerSession *) s->specific_data;
00740     int aux_int_data[] = {2};
00741     session_data->conv_on = True;
00742     
00743     lp = s->If->m->iml_make_start_conversion_inst(s);
00744     s->If->m->iml_link_inst_tail(&rrv, lp);
00745     
00746     if (session_data->preedit_start == False) {
00747         lp = s->If->m->iml_make_preedit_done_inst(s);
00748         s->If->m->iml_link_inst_tail(&rrv, lp);
00749         session_data->preedit_start = True;
00750     }
00751     lp = s->If->m->iml_execute(s, &rrv);
00752     
00753     status_draw(s);
00754 }
00755 
00756 void
00757 my_conversion_off(
00758     iml_session_t * s
00759 )
00760 {
00761     iml_inst *lp;
00762     iml_inst *rrv = NULL;
00763     int aux_int_data[] = {3};
00764     
00765     MyDataPerSession *session_data = (MyDataPerSession *) s->specific_data;
00766     session_data->conv_on = False;
00767     
00768     /* if preedit exists, commit the string */
00769     commit(s);
00770     
00771     if (session_data->luc_start == True) {
00772         lp = s->If->m->iml_make_lookup_done_inst(s);
00773         s->If->m->iml_link_inst_tail(&rrv, lp);
00774         session_data->luc_start = False;
00775     }
00776     if (session_data->preedit_start == True) {
00777         lp = s->If->m->iml_make_preedit_done_inst(s);
00778         s->If->m->iml_link_inst_tail(&rrv, lp);
00779         session_data->preedit_start = False;
00780         session_data->caret_pos = -1;
00781     }
00782     lp = s->If->m->iml_make_end_conversion_inst(s);
00783     s->If->m->iml_link_inst_tail(&rrv, lp);
00784     
00785     s->If->m->iml_execute(s, &rrv);
00786     
00787     status_draw(s);
00788 }
00789 
00790 Bool
00791 if_sampleja_SetSCValue(
00792     iml_session_t * s,
00793     IMArgList args,
00794     int num_args
00795 )
00796 {
00797     int i;
00798     IMArg *p = args;
00799     MyDataPerDesktop *desktop_data = (MyDataPerDesktop *) s->desktop->specific_data;
00800 
00801 #ifdef DEBUG
00802     printf("if_sampleja_SetSCValue()\n");
00803     printf("  s=[%x]\n", s);
00804     printf("  If=[%x]\n", s->desktop->If);
00805     printf("  desktop=[%x]\n", s->desktop);
00806     printf("  locale=[%s]\n", s->desktop->If->locale);
00807     printf("  if_name=[%s]\n", s->desktop->If->if_name);
00808     printf("  USER:%s\n", s->desktop->user_name);
00809     printf("  HOST:%s\n", s->desktop->host_name);
00810 #endif
00811     for (i = 0; i < num_args; i++, p++) {
00812         switch (p->id) {
00813             case SC_TRIGGER_ON_NOTIFY:
00814                 my_conversion_on(s);
00815                 break;
00816                 
00817             case SC_TRIGGER_OFF_NOTIFY:
00818                 my_conversion_off(s);
00819                 break;
00820                 
00821             case SC_REALIZE:
00822                 if (!desktop_data->auxproxy_session){
00823                     desktop_data->auxproxy_session = s;
00824                   printf("new auxproxy_session %x count=%d\n", desktop_data->auxproxy_session, s->desktop->session_count);
00825                     if (getenv("DONOTSTART_AUX_AT_SC_REALIZE") == NULL) {
00826                         aux_start(desktop_data->auxproxy_session, SAMPLE_AUX_PANEL);
00827                     }
00828                 }
00829                 break;
00830             case SC_LOOKUP_LABELTYPE:
00831                 break;
00832             default:
00833                 break;
00834             }
00835     }
00836     return True;
00837 }
00838 
00839 IMText *
00840 if_sampleja_ResetSC(
00841     iml_session_t * s
00842 )
00843 {
00844     int i;
00845     iml_inst *lp;
00846     IMText *p = make_preedit_imtext(s);
00847     MyDataPerSession *session_data = (MyDataPerSession *) s->specific_data;
00848     
00849 #ifdef DEBUG
00850     printf("if_sampleja_ResetSC(s=%x)\n", s);
00851     printf("  s=[%x]\n", s);
00852     printf("  If=[%x]\n", s->desktop->If);
00853     printf("  desktop=[%x]\n", s->desktop);
00854     printf("  locale=[%s]\n", s->desktop->If->locale);
00855     printf("  if_name=[%s]\n", s->desktop->If->if_name);
00856     printf("  USER:%s\n", s->desktop->user_name);
00857     printf("  HOST:%s\n", s->desktop->host_name);
00858     printf("  DISPLAY:%s\n", s->desktop->display_id);
00859 #endif
00860     
00861     /*
00862     * when you return IMText for commit string, you need to call
00863     * iml_make_preedit_erase_inst() here.
00864     */
00865     lp = s->If->m->iml_make_preedit_erase_inst(s);
00866     s->If->m->iml_execute(s, &lp);
00867     
00868     /*
00869     * reset buffer
00870     */
00871     for (i = 0; i < BUFSIZE; i++) {
00872         set_feedback(&session_data->preedit_feedback[i], IMUnderline);
00873     }
00874     memset(session_data->preedit_buf, 0, sizeof(UTFCHAR) * BUFSIZE);
00875     memset(session_data->preedit_string, 0, sizeof(UTFCHAR) * BUFSIZE);
00876     memset(session_data->conversion_string, 0, sizeof(UTFCHAR) * BUFSIZE);
00877     session_data->caret_pos = -1;
00878     
00879     /*
00880     * return committed string
00881     */
00882     if (p->char_length) {
00883         return p;
00884     }
00885     return (IMText *) NULL;
00886 }
00887 
00888 void
00889 if_sampleja_SetSCFocus(
00890     iml_session_t * s
00891 )
00892 {
00893     MyDataPerSession *session_data = (MyDataPerSession *) s->specific_data;
00894     MyDataPerDesktop *desktop_data = (MyDataPerDesktop *) s->desktop->specific_data;
00895 #ifdef DEBUG
00896     printf("if_sampleja_SetSCFocus()\n");
00897     printf("  s=[%x]\n", s);
00898     printf("  If=[%x]\n", s->desktop->If);
00899     printf("  desktop=[%x]\n", s->desktop);
00900     printf("  locale=[%s]\n", s->desktop->If->locale);
00901     printf("  if_name=[%s]\n", s->desktop->If->if_name);
00902     printf("  USER:%s\n", s->desktop->user_name);
00903     printf("  HOST:%s\n", s->desktop->host_name);
00904     printf("  DISPLAY:%s\n", s->desktop->display_id);
00905 #endif
00906     status_draw(s);
00907 }
00908 
00909 void
00910 if_sampleja_UnsetSCFocus(
00911     iml_session_t * s
00912 )
00913 {
00914 #ifdef DEBUG
00915     printf("if_sampleja_UnsetSCFocus()\n");
00916     printf("  s=[%x]\n", s);
00917     printf("  If=[%x]\n", s->desktop->If);
00918     printf("  desktop=[%x]\n", s->desktop);
00919     printf("  locale=[%s]\n", s->desktop->If->locale);
00920     printf("  if_name=[%s]\n", s->desktop->If->if_name);
00921     printf("  USER:%s\n", s->desktop->user_name);
00922     printf("  HOST:%s\n", s->desktop->host_name);
00923     printf("  DISPLAY:%s\n", s->desktop->display_id);
00924 #endif
00925     /*
00926     * status_draw(s);
00927     */
00928 }
00929 
00930 void
00931 if_sampleja_SendEvent(
00932     iml_session_t * s,
00933     IMInputEvent * ev
00934 )
00935 {
00936 #ifdef DEBUG
00937     printf("if_sampleja_SendEvent s=%x ev=%x\n", s, ev);
00938 #endif
00939     if (ev) {
00940         if (ev->type == IM_EventKeyList) {
00941             if (receive_keylist(s, (IMKeyListEvent *) ev) == False) {
00942                 IMKeyListEvent *keylist = (IMKeyListEvent *) ev;
00943                 iml_inst *lp = s->If->m->iml_make_keypress_inst(s, (IMKeyEventStruct *) keylist->keylist);
00944                 s->If->m->iml_execute(s, &lp);
00945             }
00946         } else if (ev->type == IM_EventAux) {
00947             IMAuxEvent *aux = (IMAuxEvent *) ev;
00948             IMAuxDrawCallbackStruct *data = aux->aux;
00949             receive_aux(s, data);
00950         } else if (ev->type == IM_EventString) {
00951             /* String Event */
00952         } else if (ev->type == IM_EventText) {
00953             /* Text Event */
00954         }
00955     }
00956 }
00957 
00958 typedef struct henkan_table_ {
00959     int contents;
00960     int key;
00961     int result;
00962 }   henkan_table;
00963 
00964 henkan_table htable[] = {
00965     {0, '.', 0x3002},
00966     {0, ',', 0x3001},
00967     {0, '-', 0x30fc},
00968     {0, 'a', 0x3042},
00969     {0, 'i', 0x3044},
00970     {0, 'u', 0x3046},
00971     {0, 'e', 0x3048},
00972     {0, 'o', 0x304a},
00973     {'k', 'a', 0x304b},
00974     {'k', 'i', 0x304d},
00975     {'k', 'u', 0x304f},
00976     {'k', 'e', 0x3051},
00977     {'k', 'o', 0x3053},
00978     {'n', 'a', 0x306a},
00979     {'n', 'i', 0x306b},
00980     {'n', 'u', 0x306c},
00981     {'n', 'e', 0x306d},
00982     {'n', 'o', 0x306e},
00983     {'h', 'a', 0x306f},
00984     {'h', 'i', 0x3072},
00985     {'h', 'u', 0x3075},
00986     {'h', 'e', 0x3078},
00987     {'h', 'o', 0x307b},
00988     {'m', 'a', 0x307e},
00989     {'m', 'i', 0x307f},
00990     {'m', 'u', 0x3080},
00991     {'m', 'e', 0x3081},
00992     {'m', 'o', 0x3082},
00993     {'y', 'a', 0x3084},
00994     {'y', 'i', 0x3044},
00995     {'y', 'u', 0x3086},
00996     {'y', 'e', 0x3048},
00997     {'y', 'o', 0x3088},
00998     {'r', 'a', 0x3089},
00999     {'r', 'i', 0x308a},
01000     {'r', 'u', 0x308b},
01001     {'r', 'e', 0x308c},
01002     {'r', 'o', 0x308d},
01003     {'t', 'a', 0x305f},
01004     {'t', 'i', 0x3061},
01005     {'t', 'u', 0x3064},
01006     {'t', 'e', 0x3066},
01007     {'t', 'o', 0x3068},
01008     {'s', 'a', 0x3055},
01009     {'s', 'i', 0x3057},
01010     {'s', 'u', 0x3059},
01011     {'s', 'e', 0x305b},
01012     {'s', 'o', 0x305d},
01013     {'n', 'n', 0x3093},
01014     {'d', 'a', 0x3060},
01015     {'d', 'i', 0x3062},
01016     {'d', 'u', 0x3065},
01017     {'d', 'e', 0x3067},
01018     {'d', 'o', 0x3069},
01019     {'g', 'a', 0x304c},
01020     {'g', 'i', 0x304e},
01021     {'g', 'u', 0x3050},
01022     {'g', 'e', 0x3052},
01023     {'g', 'o', 0x3054},
01024     {'z', 'a', 0x3056},
01025     {'z', 'i', 0x3058},
01026     {'z', 'u', 0x305a},
01027     {'z', 'e', 0x305c},
01028     {'z', 'o', 0x305e},
01029     {'p', 'a', 0x3071},
01030     {'p', 'i', 0x3074},
01031     {'p', 'u', 0x3077},
01032     {'p', 'e', 0x307a},
01033     {'p', 'o', 0x307d},
01034     {'b', 'a', 0x3070},
01035     {'b', 'i', 0x3073},
01036     {'b', 'u', 0x3076},
01037     {'b', 'e', 0x3079},
01038     {'b', 'o', 0x307c},
01039     {'j', 'i', 0x3058},
01040     {'w', 'a', 0x308f},
01041     {'w', 'o', 0x3092},
01042     {'l', 'a', 0x3041},
01043     {'l', 'i', 0x3043},
01044     {'l', 'u', 0x3045},
01045     {'l', 'e', 0x3047},
01046     {'l', 'o', 0x3049},
01047     {0, 0, 0}
01048 };
01049 
01050 typedef struct henkan_table2_ {
01051     char contents[3];
01052     int key;
01053     int result1;
01054     int result2;
01055 }   henkan_table2;
01056 
01057 henkan_table2 htable2[] = {
01058     {"ky", 'a', 0x304d, 0x3083},
01059     {"ky", 'u', 0x304d, 0x3085},
01060     {"ky", 'o', 0x304d, 0x3087},
01061     
01062     {"sy", 'a', 0x3057, 0x3083},
01063     {"sy", 'u', 0x3057, 0x3085},
01064     {"sy", 'o', 0x3057, 0x3087},
01065     {"sh", 'a', 0x3057, 0x3083},
01066     {"sh", 'u', 0x3057, 0x3085},
01067     {"sh", 'o', 0x3057, 0x3087},
01068     
01069     {"jy", 'a', 0x3058, 0x3083},
01070     {"jy", 'u', 0x3058, 0x3085},
01071     {"jy", 'o', 0x3058, 0x3087},
01072     
01073     {"gy", 'a', 0x304e, 0x3083},
01074     {"gy", 'u', 0x304e, 0x3085},
01075     {"gy", 'o', 0x304e, 0x3087},
01076     
01077     {"ch", 'a', 0x3061, 0x3083},
01078     {"ch", 'u', 0x3061, 0x3085},
01079     {"ch", 'o', 0x3061, 0x3087},
01080     
01081     {"dh", 'a', 0x3062, 0x3083},
01082     {"dh", 'u', 0x3062, 0x3085},
01083     {"dh", 'o', 0x3062, 0x3087},
01084     {"dy", 'a', 0x3062, 0x3083},
01085     {"dy", 'u', 0x3062, 0x3085},
01086     {"dy", 'o', 0x3062, 0x3087},
01087     
01088     {"ny", 'a', 0x306b, 0x3083},
01089     {"ny", 'u', 0x306b, 0x3085},
01090     {"ny", 'o', 0x306b, 0x3087},
01091     
01092     {"hy", 'a', 0x3072, 0x3083},
01093     {"hy", 'u', 0x3072, 0x3085},
01094     {"hy", 'o', 0x3072, 0x3087},
01095     
01096     {"by", 'a', 0x3073, 0x3083},
01097     {"by", 'u', 0x3073, 0x3085},
01098     {"by", 'o', 0x3073, 0x3087},
01099     
01100     {"py", 'a', 0x3074, 0x3083},
01101     {"py", 'u', 0x3074, 0x3085},
01102     {"py", 'o', 0x3074, 0x3087},
01103     
01104     {"my", 'a', 0x307f, 0x3083},
01105     {"my", 'u', 0x307f, 0x3085},
01106     {"my", 'o', 0x307f, 0x3087},
01107     
01108     {"ry", 'a', 0x308a, 0x3083},
01109     {"ry", 'u', 0x308a, 0x3085},
01110     {"ry", 'o', 0x308a, 0x3087},
01111     
01112     {"tt", 'e', 0x3063, 0x3066},
01113     {"tt", 'a', 0x3063, 0x305f},
01114     {(char) NULL, 0, 0, 0}
01115 };
01116 
01117 henkan_table2 htable2_1[] = {
01118     {"j", 'a', 0x3058, 0x3083},
01119     {"j", 'u', 0x3058, 0x3085},
01120     {"j", 'o', 0x3058, 0x3087},
01121     {(char) NULL, 0, 0, 0}
01122 };
01123 
01124 int hira_table[] = {
01125     0x3041, 0x3042, 0x3043, 0x3044, 0x3045, 0x3046, 0x3047, 0x3048, 0x3049, 0x304a, 0x304b, 0x304c, 0x304d, 0x304e, 0x304f,
01126     0x3050, 0x3051, 0x3052, 0x3053, 0x3054, 0x3055, 0x3056, 0x3057, 0x3058, 0x3059, 0x305a, 0x305b, 0x305c, 0x305d, 0x305e, 0x305f,
01127     0x3060, 0x3061, 0x3062, 0x3063, 0x3064, 0x3065, 0x3066, 0x3067, 0x3068, 0x3069, 0x306a, 0x306b, 0x306c, 0x306d, 0x306e, 0x306f,
01128     0x3070, 0x3071, 0x3072, 0x3073, 0x3074, 0x3075, 0x3076, 0x3077, 0x3078, 0x3079, 0x307a, 0x307b, 0x307c, 0x307d, 0x307e, 0x307f,
01129     0x3080, 0x3081, 0x3082, 0x3083, 0x3084, 0x3085, 0x3086, 0x3087, 0x3088, 0x3089, 0x308a, 0x308b, 0x308c, 0x308d, 0x308e, 0x308f,
01130     0x3090, 0x3091, 0x3092, 0x3093, 0x0
01131 };
01132 
01133 int kana_table[] = {
01134     0x30a1, 0x30a2, 0x30a3, 0x30a4, 0x30a5, 0x30a6, 0x30a7, 0x30a8, 0x30a9, 0x30aa, 0x30ab, 0x30ac, 0x30ad, 0x30ae, 0x30af,
01135     0x30b0, 0x30b1, 0x30b2, 0x30b3, 0x30b4, 0x30b5, 0x30b6, 0x30b7, 0x30b8, 0x30b9, 0x30ba, 0x30bb, 0x30bc, 0x30bd, 0x30be, 0x30bf,
01136     0x30c0, 0x30c1, 0x30c2, 0x30c3, 0x30c4, 0x30c5, 0x30c6, 0x30c7, 0x30c8, 0x30c9, 0x30ca, 0x30cb, 0x30cc, 0x30cd, 0x30ce, 0x30cf,
01137     0x30d0, 0x30d1, 0x30d2, 0x30d3, 0x30d4, 0x30d5, 0x30d6, 0x30d7, 0x30d8, 0x30d9, 0x30da, 0x30db, 0x30dc, 0x30dd, 0x30de, 0x30df,
01138     0x30e0, 0x30e1, 0x30e2, 0x30e3, 0x30e4, 0x30e5, 0x30e6, 0x30e7, 0x30e8, 0x30e9, 0x30ea, 0x30eb, 0x30ec, 0x30ed, 0x30ee, 0x30ef,
01139     0x30f0, 0x30f1, 0x30f2, 0x30f3, 0x30f4, 0x30f5, 0x30f6, 0x0,
01140 };
01141 
01142 
01143 /*
01144  * UTFCHAR naoyuki_string[] = {0x3044,0x3057,0x3080,0x3089}
01145  */
01146 
01147 Bool
01148 receive_keylist(
01149     iml_session_t * s,
01150     IMKeyListEvent * keylist
01151 )
01152 {
01153     int i;
01154     int m;
01155     int j;
01156     IMKeyEventStruct *k = (IMKeyEventStruct *) keylist->keylist;
01157     MyDataPerSession *session_data = (MyDataPerSession *) s->specific_data;
01158     MyDataPerDesktop *desktop_data = (MyDataPerDesktop *) s->desktop->specific_data;
01159     i = UTFCHARLen(session_data->preedit_buf);
01160 
01161     printf("iml_session_t() keycode=%x,keychar=%x, state=%x\n", k->keyCode, k->keyChar, k->modifier);
01162     
01163     if (session_data->luc_start == True) {
01164         int index = 0;
01165         if (session_data->luc_type == IMIsMaster) {
01166             if ('1' <= k->keyChar && '9' >= k->keyChar) {
01167                 index = k->keyChar - '1';
01168             } else if ('A' <= k->keyChar && 'Z' >= k->keyChar) {
01169                 index = k->keyChar - 'A' + 9;
01170             } else if ('a' <= k->keyChar && 'z' >= k->keyChar) {
01171                 index = k->keyChar - 'a' + 35;
01172             } else if (k->modifier & IM_CTRL_MASK) {
01173                 if (k->keyCode == IM_VK_N) {
01174                     lookup_next(s);
01175                     lookup_test(s);
01176                 } else if (k->keyCode == IM_VK_P) {
01177                     lookup_prev(s);
01178                     lookup_test(s);
01179                 }
01180                 return True;
01181             } else if (k->keyCode == IM_VK_ENTER || k->keyCode == IM_VK_ACCEPT) {
01182                 index = session_data->luc_current_candidate;
01183             } else if (k->keyCode == IM_VK_SPACE || k->keyCode == IM_VK_CONVERT) {
01184                 session_data->luc_current_candidate++;
01185                 if (session_data->luc_current_candidate == session_data->luc_nchoices) {
01186                     lookup_next(s);
01187                 }
01188                 if (session_data->luc_top + session_data->luc_current_candidate > session_data->max_candidates) {
01189                     lookup_next(s);
01190                 }
01191                 lookup_test(s);
01192                 return True;
01193             } else {
01194                 return True;
01195             }
01196             if (index >= session_data->luc_nchoices) {
01197                 return True;
01198             }
01199             lookup_commit(s, index);
01200         }
01201         return True;
01202     }
01203     if (k->modifier & IM_CTRL_MASK) {
01204         switch (k->keyCode) {
01205             case IM_VK_SPACE:
01206             case IM_VK_SLASH:
01207                 my_conversion_off(s);
01208                 return True;
01209                 break;
01210             case IM_VK_I:
01211                 if (i > 0) {
01212                     to_kana(s);
01213                     return True;
01214                 } else {
01215                     return False;
01216                 }
01217                 break;
01218             case IM_VK_U:
01219                 if (i > 0) {
01220                     to_hira(s);
01221                     return True;
01222                 } else {
01223                     return False;
01224                 }
01225                 break;
01226             case IM_VK_LEFT:
01227                 if (i > 0) {
01228                     caret_move_left(s);
01229                     return True;
01230                 } else {
01231                     return False;
01232                 }
01233                 break;
01234             case IM_VK_RIGHT:
01235                 if (i > 0) {
01236                     caret_move_right(s);
01237                     return True;
01238                 } else {
01239                     return False;
01240                 }
01241                 break;
01242             case IM_VK_L:
01243                 if (i > 0) {
01244                     expand_preedit(s);
01245                     return True;
01246                 } else {
01247                     return False;
01248                 }
01249                 break;
01250             case IM_VK_K:
01251                 if (i > 0) {
01252                     shrink_preedit(s);
01253                     return True;
01254                 } else {
01255                     return False;
01256                 }
01257                 break;
01258             case IM_VK_N:
01259                 if (i > 0) {
01260                     commit_partial(s);
01261                     return True;
01262                 } else {
01263                     return False;
01264                 }
01265                 break;
01266             case IM_VK_J:
01267                 if (i > 4) {
01268                     iml_make_preedit_draw_with_chgpos_inst_test(s);
01269                     return True;
01270                 } else {
01271                     return False;
01272                 }
01273             case IM_VK_Q:
01274                 aux_start(desktop_data->auxproxy_session, SAMPLE_AUX_PANEL);
01275                 break;
01276             case IM_VK_W:
01277                 {
01278                     
01279                     int aux_int_data[] = {3};
01280                     
01281                     static UTFCHAR aux_candidate1[] = {'1', ' ', 0x304b, 0x3093, 0x3058, 0x0};
01282                     static UTFCHAR aux_candidate2[] = {'2', ' ', 0x52d8, 0x6b21, 0x0};
01283                     static UTFCHAR aux_candidate3[] = {'3', ' ', 0x611f, 0x3058, 0x0};
01284                     static UTFCHAR aux_candidate4[] = {'4', ' ', 0x6f22, 0x5b57, 0x0};
01285                     static UTFCHAR aux_candidate5[] = {'5', ' ', 0x76e3, 0x4e8b, 0x0};
01286                     static UTFCHAR aux_candidate6[] = {'6', ' ', 0x5b8c, 0x6cbb, 0x0};
01287                     static UTFCHAR aux_candidate7[] = {'7', ' ', 0x5e79, 0x4e8b, 0x0};
01288                     static UTFCHAR aux_candidate8[] = {'8', ' ', 0x5bdb, 0x4e8c, 0x0};
01289                     static UTFCHAR aux_candidate9[] = {'9', ' ', 0x5bdb, 0x53f8, 0x0};
01290                     
01291                     UTFCHAR *aux_string_data[] = {
01292                         aux_candidate1,
01293                         aux_candidate2,
01294                         aux_candidate3,
01295                         aux_candidate4,
01296                         aux_candidate5,
01297                         aux_candidate6,
01298                         aux_candidate7,
01299                         aux_candidate8,
01300                         aux_candidate9,
01301                     };
01302                     
01303                     if (desktop_data->aux_start[SAMPLE_AUX_DICT] == False) {
01304                         aux_start(s, SAMPLE_AUX_DICT);
01305                     }
01306                     aux_draw(s, SAMPLE_AUX_DICT, 1, aux_int_data, 9, aux_string_data);
01307                 }
01308                 break;
01309             case IM_VK_E:
01310                 {
01311                     int aux_int_data[] = {1};
01312                     UTFCHAR *aux_string_data[] = {candidate_string};
01313                     if (desktop_data->aux_start[SAMPLE_AUX_PANEL] == False) {
01314                         aux_start(desktop_data->auxproxy_session, SAMPLE_AUX_PANEL);
01315                     }
01316                     aux_draw(desktop_data->auxproxy_session, SAMPLE_AUX_PANEL, 1, aux_int_data, 1, aux_string_data);
01317                 }
01318                 break;
01319             case IM_VK_R:
01320                 list_test(s);
01321                 break;
01322             default:
01323                 return False;
01324                 break;
01325             }
01326         return True;
01327     }
01328     if (k->keyCode == IM_VK_KANJI) {
01329        my_conversion_off(s);
01330     } else if (k->keyCode == IM_VK_HOME) {
01331         if (i > 0) {
01332             caret_move_home(s);
01333             return True;
01334         } else {
01335             return False;
01336         }
01337     } else if (k->keyCode == IM_VK_END) {
01338         if (i > 0) {
01339             caret_move_end(s);
01340             return True;
01341         } else {
01342             return False;
01343         }
01344     } else if (k->keyCode == IM_VK_ENTER || k->keyCode == IM_VK_ACCEPT) {
01345         if (i > 0) {
01346             commit(s);
01347             return True;
01348         } else {
01349             return False;
01350         }
01351     } else if (k->keyCode == IM_VK_BACK_SPACE) {
01352         if (i > 0) {
01353             session_data->preedit_buf[i - 1] = 0;
01354             preedit_draw(s);
01355             return True;
01356         } else {
01357             return False;
01358         }
01359     } else if (k->keyCode == IM_VK_RIGHT) {
01360         if (i > 0) {
01361             expand_preedit(s);
01362             return True;
01363         } else {
01364             return False;
01365         }
01366     } else if (k->keyCode == IM_VK_LEFT) {
01367         if (i > 0) {
01368             shrink_preedit(s);
01369             return True;
01370         } else {
01371             return False;
01372         }
01373     } else if (k->keyCode == IM_VK_DOWN) {
01374         if (i > 0) {
01375             commit_partial(s);
01376             return True;
01377         } else {
01378             return False;
01379         }
01380     } else if (k->keyCode == IM_VK_SPACE ||
01381       k->keyCode == IM_VK_CONVERT) {
01382         if (i > 0) {
01383             if (do_convert(s) == True) {
01384                 return True;
01385             }
01386             preedit_draw_reverse(s);
01387             return True;
01388         } else {
01389             return False;
01390         }
01391     } else if (k->keyChar >= '!' && k->keyChar <= '~') {
01392         m = 0;
01393         if (i > 1) {
01394             char last2[3];
01395             last2[0] = (char) session_data->preedit_buf[i - 2];
01396             last2[1] = (char) session_data->preedit_buf[i - 1];
01397             last2[2] = '\0';
01398 #ifdef notdef
01399             printf("last0=%x last1=%x keychar=%x\n", last2[0], last2[1], k->keyChar);
01400             printf("%s\n", last2);
01401 #endif
01402             if (last2[0] <= 'z' && last2[1] <= 'z') {
01403                 for (j = 0; htable2[j].key; j++) {
01404                     if (htable2[j].key == k->keyChar &&
01405                       !strcmp(htable2[j].contents, last2)) {
01406                         session_data->preedit_buf[i - 2] = htable2[j].result1;
01407                         session_data->preedit_buf[i - 1] = htable2[j].result2;
01408                         session_data->preedit_buf[i] = 0;
01409                         set_feedback(&session_data->preedit_feedback[i - 2], IMUnderline);
01410                         set_feedback(&session_data->preedit_feedback[i - 1], IMUnderline);
01411                         m = 1;
01412                         break;
01413                     }
01414                 }
01415             }
01416         }
01417         if (m == 0) {
01418             if (i > 0) {
01419                 int last = session_data->preedit_buf[i - 1];
01420                 if (last > 'z') {
01421                     last = 0;
01422                 }
01423                 for (j = 0; htable2_1[j].key; j++) {
01424                     if (htable2_1[j].key == k->keyChar &&
01425                       htable2_1[j].contents[0] == last) {
01426                         session_data->preedit_buf[i - 1] = htable2_1[j].result1;
01427                         session_data->preedit_buf[i] = htable2_1[j].result2;
01428                         session_data->preedit_buf[i + 1] = 0;
01429                         set_feedback(&session_data->preedit_feedback[i - 1], IMUnderline);
01430                         set_feedback(&session_data->preedit_feedback[i], IMUnderline);
01431                         m = 1;
01432                         break;
01433                     }
01434                 }
01435                 if (m == 0) {
01436                     for (j = 0; htable[j].key; j++) {
01437                         if (htable[j].key == k->keyChar &&
01438                           htable[j].contents == last) {
01439                             if (last == 0) {
01440                                 session_data->preedit_buf[i] = htable[j].result;
01441                                 session_data->preedit_buf[i + 1] = 0;
01442                                 set_feedback(&session_data->preedit_feedback[i], IMUnderline);
01443                             } else {
01444                                 session_data->preedit_buf[i - 1] = htable[j].result;
01445                                 session_data->preedit_buf[i] = 0;
01446                                 set_feedback(&session_data->preedit_feedback[i - 1], IMUnderline);
01447                             }
01448                             m = 1;
01449                             break;
01450                         }
01451                     }
01452                 }
01453             } else {
01454                 /* i == 0 */
01455                 for (j = 0; htable[j].key; j++) {
01456                     if (htable[j].key == k->keyChar &&
01457                       htable[j].contents == 0) {
01458                         session_data->preedit_buf[0] = htable[j].result;
01459                         session_data->preedit_buf[1] = 0;
01460                         set_feedback(&session_data->preedit_feedback[0], IMUnderline);
01461                         m = 1;
01462                         break;
01463                     }
01464                 }
01465             }
01466         }
01467         if (m == 0) {
01468             session_data->preedit_buf[i] = k->keyChar;
01469             session_data->preedit_buf[i + 1] = 0;
01470             set_feedback(&session_data->preedit_feedback[i], IMUnderline);
01471         }
01472     } else {
01473         return False;
01474     }
01475     
01476 #ifdef DEBUG
01477     printf("  keycode=%x,keychar=%x, state=%x\n", k->keyCode, k->keyChar, k->modifier);
01478 #endif
01479     
01480     preedit_draw(s);
01481     
01482 #ifdef notdef
01483     IMOperation *op;
01484     for (i = 0, k = (IMKeyEventStruct *) keylist->keylist; i < keylist->n_key; i++, k++) {
01485         printf("k->keyCode=%x\n", k->keyCode);
01486         printf("k->keyChar=%x\n", k->keyChar);
01487         printf("k->modifier=%x\n", k->modifier);
01488         if (keylist->operation_list) {
01489             for (i = 0, op = (IMOperation *) keylist->operation_list; i < keylist->n_operation; i++, op++) {
01490                 printf("op->id=%d\n", op->id);
01491                 printf("op->length=%d\n", op->length);
01492                 printf("op->value=[%s]\n", op->value);
01493             }
01494         }
01495     }
01496 #endif
01497     return True;
01498 }
01499 
01500 UTFCHARCat(
01501     UTFCHAR * dest,
01502     UTFCHAR * str1,
01503     UTFCHAR * str2
01504 )
01505 {
01506     int i;
01507     for (i = 0; *str1; i++) {
01508         *dest++ = *str1++;
01509     }
01510     for (i = 0; *str2; i++) {
01511         *dest++ = *str2++;
01512     }
01513     *dest = 0;
01514     return i;
01515 }
01516 
01517 Bool
01518 UTFCHARCmp(
01519     UTFCHAR * s1,
01520     UTFCHAR * s2
01521 )
01522 {
01523     int i;
01524     if (UTFCHARLen(s1) != UTFCHARLen(s2)) {
01525         return False;
01526     }
01527     for (i = 0; i < UTFCHARLen(s1); i++) {
01528         if (s1[i] != s2[i]) {
01529             return False;
01530         }
01531     }
01532     return True;
01533 }
01534 
01535 Bool
01536 UTFCHARCmp2(
01537     UTFCHAR * s1,
01538     char *s2,
01539     int len
01540 )
01541 {
01542     int i;
01543     for (i = 0; i < len; i++) {
01544         if (s2[i] == 0) {
01545             return False;
01546         }
01547         if (s1[i] != s2[i]) {
01548             return False;
01549         }
01550     }
01551     if (s2[i] != 0) {
01552         return False;
01553     }
01554     return True;
01555 }
01556 
01557 int
01558 UTFCHARCpy(
01559     UTFCHAR * dest,
01560     UTFCHAR * original
01561 )
01562 {
01563     int i;
01564     for (i = 0; *original; i++) {
01565         *dest++ = *original++;
01566     }
01567     *dest = 0;
01568     return i;
01569 }
01570 
01571 int
01572 UTFCHARLen(
01573     UTFCHAR * p
01574 )
01575 {
01576     int i;
01577     for (i = 0; *p; i++)
01578     p++;
01579     return i;
01580 }
01581 
01582 void
01583 to_hira(
01584     iml_session_t * s
01585 )
01586 {
01587     int i, j;
01588     MyDataPerSession *session_data = (MyDataPerSession *) s->specific_data;
01589     
01590     for (i = 0; session_data->preedit_buf[i]; i++) {
01591         int hira = session_data->preedit_buf[i];
01592         for (j = 0; kana_table[j]; j++) {
01593             if (session_data->preedit_buf[i] == kana_table[j]) {
01594                 hira = hira_table[j];
01595             }
01596         }
01597         session_data->preedit_buf[i] = hira;
01598     }
01599     
01600     preedit_draw(s);
01601 }
01602 
01603 void
01604 to_kana(
01605     iml_session_t * s
01606 )
01607 {
01608     MyDataPerSession *session_data = (MyDataPerSession *) s->specific_data;
01609     
01610     int i, j;
01611     for (i = 0; session_data->preedit_buf[i]; i++) {
01612         int kana = session_data->preedit_buf[i];
01613         for (j = 0; hira_table[j]; j++) {
01614             if (session_data->preedit_buf[i] == hira_table[j]) {
01615                 kana = kana_table[j];
01616             }
01617         }
01618         session_data->preedit_buf[i] = kana;
01619     }
01620     
01621     preedit_draw(s);
01622 }
01623 
01624 void
01625 commit_onechar(
01626     iml_session_t * s,
01627     int achar
01628 )
01629 {
01630     int i;
01631     iml_inst *lp;
01632     IMFeedbackList *fbl;
01633     IMFeedback *fb;
01634     MyDataPerSession *session_data = (MyDataPerSession *) s->specific_data;
01635     
01636     IMText *p = (IMText *) s->If->m->iml_new(s, sizeof(IMText));
01637     memset(p, 0, sizeof(IMText));
01638     p->encoding = UTF16_CODESET;
01639     p->text.utf_chars = (UTFCHAR *) s->If->m->iml_new(s, sizeof(UTFCHAR) * 2);
01640     p->text.utf_chars[0] = achar;
01641     p->text.utf_chars[1] = 0;
01642     p->char_length = 1;
01643     p->feedback = create_feedback(s, p->char_length);
01644     lp = s->If->m->iml_make_commit_inst(s, p);
01645     s->If->m->iml_execute(s, &lp);
01646 }
01647 
01648 void
01649 commit_partial(
01650     iml_session_t * s
01651 )
01652 {
01653     int i;
01654     int len;
01655     int last_reverse = -1;
01656     iml_inst *lp;
01657     iml_inst *rrv = NULL;
01658     IMText *p;
01659     MyDataPerSession *session_data = (MyDataPerSession *) s->specific_data;
01660     len = UTFCHARLen(session_data->preedit_buf);
01661     
01662     for (i = 0; i < len; i++) {
01663         if (get_feedback(&session_data->preedit_feedback[i]) == IMReverse) {
01664             last_reverse = i;
01665         }
01666     }
01667     
01668     if (last_reverse == -1 || (last_reverse + 1) == len) {
01669         /* commit whole preedit */
01670         commit(s);
01671         return;
01672     }
01673     p = (IMText *) s->If->m->iml_new(s, sizeof(IMText));
01674     memset(p, 0, sizeof(IMText));
01675     p->encoding = UTF16_CODESET;
01676     p->text.utf_chars = (UTFCHAR *) s->If->m->iml_new(s, sizeof(UTFCHAR) * (last_reverse + 1));
01677     for (i = 0; i <= last_reverse; i++) {
01678         p->text.utf_chars[i] = session_data->preedit_buf[i];
01679     }
01680     
01681     p->char_length = last_reverse + 1;
01682     p->feedback = create_feedback(s, p->char_length);
01683     
01684     for (i = (last_reverse + 1);; i++) {
01685         session_data->preedit_buf[i - (last_reverse + 1)] = session_data->preedit_buf[i];
01686         set_feedback(&session_data->preedit_feedback[i - (last_reverse + 1)],
01687             get_feedback(&session_data->preedit_feedback[i]));
01688         if (session_data->preedit_buf[i - (last_reverse + 1)] == 0) {
01689             break;
01690         }
01691     }
01692     
01693     /* erase first */
01694     lp = s->If->m->iml_make_preedit_erase_inst(s);
01695     s->If->m->iml_link_inst_tail(&rrv, lp);
01696     
01697     lp = s->If->m->iml_make_commit_inst(s, p);
01698     s->If->m->iml_link_inst_tail(&rrv, lp);
01699     
01700     s->If->m->iml_execute(s, &rrv);
01701     
01702     preedit_draw(s);
01703     
01704     session_data->caret_pos = -1;
01705 }
01706 
01707 void
01708 commit(
01709     iml_session_t * s
01710 )
01711 {
01712     int len, i;
01713     iml_inst *lp;
01714     iml_inst *rrv = NULL;
01715     MyDataPerSession *session_data = (MyDataPerSession *) s->specific_data;
01716     IMText *p = (IMText *) s->If->m->iml_new(s, sizeof(IMText));
01717     memset(p, 0, sizeof(IMText));
01718     p->encoding = UTF16_CODESET;
01719     
01720     len = UTFCHARLen(session_data->preedit_buf);
01721     
01722     if (len == 0) {
01723         /* no preedit */
01724         return;
01725     }
01726     lp = s->If->m->iml_make_preedit_erase_inst(s);
01727     s->If->m->iml_link_inst_tail(&rrv, lp);
01728     
01729     p->text.utf_chars = (UTFCHAR *) s->If->m->iml_new(s, sizeof(UTFCHAR) * (len + 1));
01730     UTFCHARCpy(p->text.utf_chars, session_data->preedit_buf);
01731     p->char_length = len;
01732     p->feedback = create_feedback(s, p->char_length);
01733     
01734     lp = s->If->m->iml_make_commit_inst(s, p);
01735     s->If->m->iml_link_inst_tail(&rrv, lp);
01736     s->If->m->iml_execute(s, &rrv);
01737     
01738     for (i = 0; i < BUFSIZE; i++) {
01739         set_feedback(&session_data->preedit_feedback[i], IMUnderline);
01740     }
01741     
01742     memset(session_data->preedit_buf, 0, sizeof(UTFCHAR) * BUFSIZE);
01743     memset(session_data->preedit_string, 0, sizeof(UTFCHAR) * BUFSIZE);
01744     memset(session_data->conversion_string, 0, sizeof(UTFCHAR) * BUFSIZE);
01745     
01746     session_data->caret_pos = -1;
01747 }
01748 
01749 void
01750 list_test(iml_session_t * s)
01751 {
01752     iml_session_t *p = s->desktop->session_list;
01753     while (p) {
01754         iml_inst *lp = p->If->m->iml_make_status_draw_inst(p, make_imtext(p, candidate_string));
01755         p->If->m->iml_execute(p, &lp);
01756         
01757         if (p->next)
01758             p = p->next;
01759         else
01760         break;
01761     }
01762 }
01763 
01764 void
01765 status_draw(
01766     iml_session_t * s
01767 )
01768 {
01769     int len, i;
01770     iml_inst *lp;
01771     iml_inst *rrv = NULL;
01772     UTFCHAR *str;
01773     MyDataPerSession *session_data = (MyDataPerSession *) s->specific_data;
01774     MyDataPerDesktop *desktop_data = (MyDataPerDesktop *) s->desktop->specific_data;
01775     IMText *p = (IMText *) s->If->m->iml_new(s, sizeof(IMText));
01776 
01777     int aux_int_data_convon[] = {2};
01778     int aux_int_data_convoff[] = {3};
01779 
01780     memset(p, 0, sizeof(IMText));
01781     p->encoding = UTF16_CODESET;
01782     
01783     if (session_data->conv_on) {
01784         str = on_string;
01785         aux_draw(desktop_data->auxproxy_session, SAMPLE_AUX_PANEL, 1, aux_int_data_convon, 0, NULL);
01786     } else {
01787         str = off_string;
01788         aux_draw(desktop_data->auxproxy_session, SAMPLE_AUX_PANEL, 1, aux_int_data_convoff, 0, NULL);
01789     }
01790     
01791     len = UTFCHARLen(str);
01792     p->text.utf_chars = (UTFCHAR *) s->If->m->iml_new(s, sizeof(UTFCHAR) * (len + 1));
01793     
01794     UTFCHARCpy(p->text.utf_chars, str);
01795     
01796     p->char_length = len;
01797     
01798 #ifdef USE_COLOR_FEEDBACK
01799         if (0) {
01800             /* specified both fg and bg */
01801             p->feedback = create_feedback_with_color(s, p->char_length,
01802                 IMNormal,
01803                 IM_RGB_COLOR(255, 0, 0),
01804             IM_RGB_COLOR(255, 192, 203));
01805         }
01806         if (0) {
01807             /* specified only bg */
01808             p->feedback = create_feedback_with_color(s, p->char_length,
01809                 IMNormal,
01810                 -1,
01811                 IM_RGB_COLOR(255, 192, 203));
01812         }
01813         if (0) {
01814             /* specified only fg */
01815             p->feedback = create_feedback_with_color(s, p->char_length,
01816                 IMNormal,
01817                 IM_RGB_COLOR(255, 0, 0),
01818             -1);
01819         }
01820         p->feedback = create_feedback(s, p->char_length);
01821         for (i = 0; i < 3; i++) {
01822             set_feedback_private(&p->feedback[i],
01823                 IMNormal,
01824                 IM_RGB_COLOR(255, 0, 0),
01825             IM_RGB_COLOR(255, 192, 203),
01826             -1);
01827         }
01828         if (session_data->conv_on) {
01829             for (i = 3; i < 5; i++) {
01830                 set_feedback_private(&p->feedback[i],
01831                     IMNormal,
01832                     IM_RGB_COLOR(0, 0, 0),
01833                 IM_RGB_COLOR(255, 255, 0),
01834                 -1);
01835             }
01836             
01837         } else {
01838             for (i = 3; i < 5; i++) {
01839                 set_feedback_private(&p->feedback[i],
01840                     IMNormal,
01841                     IM_RGB_COLOR(0, 0, 0),
01842                 IM_RGB_COLOR(192, 192, 192),
01843                 -1);
01844             }
01845             
01846         }
01847 #else
01848         p->feedback = create_feedback(s, p->char_length);
01849 #endif
01850     
01851     if (session_data->status_start == False) {
01852         lp = s->If->m->iml_make_status_start_inst(s);
01853         s->If->m->iml_link_inst_tail(&rrv, lp);
01854         session_data->status_start = True;
01855     }
01856     lp = s->If->m->iml_make_status_draw_inst(s, p);
01857     s->If->m->iml_link_inst_tail(&rrv, lp);
01858     
01859     s->If->m->iml_execute(s, &rrv);
01860 }
01861 
01862 /*
01863  * test for iml_make_preedit_caret_inst()
01864  */
01865 void
01866 caret_move_right(
01867     iml_session_t * s
01868 )
01869 {
01870     iml_inst *lp;
01871     int len;
01872     MyDataPerSession *session_data = (MyDataPerSession *) s->specific_data;
01873     len = UTFCHARLen(session_data->preedit_buf);
01874     if (session_data->caret_pos == -1) {
01875         session_data->caret_pos = len;
01876     }
01877     session_data->caret_pos++;
01878     
01879     if (session_data->caret_pos > len) {
01880         session_data->caret_pos = 0;
01881     }
01882 #ifdef notdef
01883     printf("iml_make_preedit_caret_inst()\n");
01884     printf("  caret_pos=%d\n", session_data->caret_pos);
01885 #endif
01886     
01887     lp = s->If->m->iml_make_preedit_caret_inst(s, session_data->caret_pos);
01888     s->If->m->iml_execute(s, &lp);
01889 }
01890 
01891 /*
01892  * test for iml_make_preedit_caret_inst()
01893  */
01894 
01895 void
01896 caret_move_left(
01897     iml_session_t * s
01898 )
01899 {
01900     int len;
01901     iml_inst *lp;
01902     MyDataPerSession *session_data = (MyDataPerSession *) s->specific_data;
01903     len = UTFCHARLen(session_data->preedit_buf);
01904     if (session_data->caret_pos == -1) {
01905         session_data->caret_pos = len;
01906     }
01907     session_data->caret_pos--;
01908     if (session_data->caret_pos == -1) {
01909         session_data->caret_pos = len;
01910     }
01911 #ifdef notdef
01912     printf("iml_make_preedit_caret_inst()\n");
01913     printf("  caret_pos=%d\n", session_data->caret_pos);
01914 #endif
01915     lp = s->If->m->iml_make_preedit_caret_inst(s, session_data->caret_pos);
01916     s->If->m->iml_execute(s, &lp);
01917 }
01918 
01919 /*
01920  * test for iml_make_preedit_caret_inst()
01921  */
01922 void
01923 caret_move_home(
01924     iml_session_t * s
01925 )
01926 {
01927     iml_inst *lp;
01928     int len;
01929     MyDataPerSession *session_data = (MyDataPerSession *) s->specific_data;
01930     len = UTFCHARLen(session_data->preedit_buf);
01931     
01932     session_data->caret_pos = 0;
01933     
01934 #ifdef notdef
01935     printf("iml_make_preedit_caret_inst()\n");
01936     printf("  caret_pos=%d\n", session_data->caret_pos);
01937 #endif
01938     
01939     lp = s->If->m->iml_make_preedit_caret_inst(s, session_data->caret_pos);
01940     s->If->m->iml_execute(s, &lp);
01941 }
01942 
01943 /*
01944  * test for iml_make_preedit_caret_inst()
01945  */
01946 
01947 void
01948 caret_move_end(
01949     iml_session_t * s
01950 )
01951 {
01952     int len;
01953     iml_inst *lp;
01954     MyDataPerSession *session_data = (MyDataPerSession *) s->specific_data;
01955     len = UTFCHARLen(session_data->preedit_buf);
01956     session_data->caret_pos = len;
01957     
01958 #ifdef notdef
01959     printf("iml_make_preedit_caret_inst()\n");
01960     printf("  caret_pos=%d\n", session_data->caret_pos);
01961 #endif
01962     
01963     lp = s->If->m->iml_make_preedit_caret_inst(s, session_data->caret_pos);
01964     s->If->m->iml_execute(s, &lp);
01965 }
01966 
01967 void
01968 expand_preedit(
01969     iml_session_t * s
01970 )
01971 {
01972     int i, len;
01973     int first_underline = -1;
01974     MyDataPerSession *session_data = (MyDataPerSession *) s->specific_data;
01975     len = UTFCHARLen(session_data->preedit_buf);
01976     
01977     memset(session_data->preedit_string, 0, sizeof(UTFCHAR) * BUFSIZE);
01978     memset(session_data->conversion_string, 0, sizeof(UTFCHAR) * BUFSIZE);
01979     
01980     for (i = 0; i < len; i++) {
01981         if (get_feedback(&session_data->preedit_feedback[i]) == IMUnderline) {
01982             first_underline = i;
01983             break;
01984         }
01985     }
01986     
01987     if (first_underline != -1) {
01988         set_feedback(&session_data->preedit_feedback[first_underline], IMReverse);
01989         preedit_draw(s);
01990     }
01991 }
01992 
01993 
01994 void
01995 shrink_preedit(
01996     iml_session_t * s
01997 )
01998 {
01999     int i, len;
02000     int last_reverse = -1;
02001     MyDataPerSession *session_data = (MyDataPerSession *) s->specific_data;
02002     len = UTFCHARLen(session_data->preedit_buf);
02003     
02004     memset(session_data->preedit_string, 0, sizeof(UTFCHAR) * BUFSIZE);
02005     memset(session_data->conversion_string, 0, sizeof(UTFCHAR) * BUFSIZE);
02006     
02007     for (i = 0; i < len; i++) {
02008         if (get_feedback(&session_data->preedit_feedback[i]) == IMReverse) {
02009             last_reverse = i;
02010         }
02011     }
02012     
02013     if (last_reverse != -1) {
02014         set_feedback(&session_data->preedit_feedback[last_reverse], IMUnderline);
02015         preedit_draw(s);
02016     }
02017 }
02018 
02019 void
02020 preedit_draw_reverse(
02021     iml_session_t * s
02022 )
02023 {
02024     int i, len;
02025     int last_reverse = -1;
02026     int buf[BUFSIZE];
02027     int fbs[BUFSIZE];
02028     MyDataPerSession *session_data = (MyDataPerSession *) s->specific_data;
02029     len = UTFCHARLen(session_data->preedit_buf);
02030     
02031     /*
02032     * when reversed once, next is convert
02033     */
02034     
02035     for (i = 0; i < len; i++) {
02036         if (get_feedback(&session_data->preedit_feedback[i]) == IMReverse) {
02037             last_reverse = i;
02038         }
02039     }
02040     
02041     if (last_reverse != -1) {
02042         if (session_data->conversion_string[0] != 0) {
02043             lookup_test(s);
02044             return;
02045         }
02046         for (i = 0; i <= last_reverse; i++) {
02047             buf[i] = session_data->preedit_buf[i];
02048 #ifdef notdef
02049             printf("buf[%d]=%x\n", i, buf[i]);
02050 #endif
02051             fbs[i] = IMReverse;
02052             session_data->conversion_string[i] = buf[i];
02053         }
02054         
02055         buf[i] = '0';
02056 #ifdef notdef
02057         printf("buf[%d]=%x\n", i, buf[i]);
02058 #endif
02059         fbs[i] = IMReverse;
02060         session_data->conversion_string[i] = 0;
02061         
02062         if (last_reverse <= UTFCHARLen(session_data->preedit_buf)) {
02063             for (i = last_reverse + 1; i < len; i++) {
02064                 buf[i + 1] = session_data->preedit_buf[i];
02065                 fbs[i + 1] = IMUnderline;
02066                 session_data->preedit_string[i - last_reverse - 1] = session_data->preedit_buf[i];
02067             }
02068             buf[i + 1] = 0;
02069             session_data->preedit_string[i - last_reverse - 1] = 0;
02070             
02071             for (i = 0; i < len + 1; i++) {
02072                 session_data->preedit_buf[i] = buf[i];
02073                 set_feedback(&session_data->preedit_feedback[i], fbs[i]);
02074             }
02075             
02076             session_data->preedit_buf[i] = 0;
02077             preedit_buf_print(s);
02078         }
02079         preedit_draw(s);
02080         return;
02081     }
02082     for (i = 0; i < len; i++) {
02083         set_feedback(&session_data->preedit_feedback[i], IMReverse);
02084     }
02085     preedit_draw(s);
02086 }
02087 
02088 void
02089 preedit_buf_print(iml_session_t * s)
02090 {
02091     int i;
02092     MyDataPerSession *session_data = (MyDataPerSession *) s->specific_data;
02093     int len = UTFCHARLen(session_data->preedit_buf);
02094     for (i = 0; i <= len; i++) {
02095         printf("Preedit[%d]=%x     %x\n",
02096             i,
02097             session_data->preedit_buf[i],
02098             get_feedback(&session_data->preedit_feedback[i]));
02099     }
02100 }
02101 
02102 IMText *
02103 make_imtext(iml_session_t * s, UTFCHAR * u)
02104 {
02105     int len;
02106     IMText *p = (IMText *) s->If->m->iml_new(s, sizeof(IMText));
02107     memset(p, 0, sizeof(IMText));
02108     p->encoding = UTF16_CODESET;
02109     len = UTFCHARLen(u);
02110     p->text.utf_chars = (UTFCHAR *) s->If->m->iml_new(s, sizeof(UTFCHAR) * (len + 1));
02111     UTFCHARCpy(p->text.utf_chars, u);
02112     p->char_length = len;
02113     p->feedback = create_feedback(s, p->char_length);
02114     return p;
02115 }
02116 
02117 IMText *
02118 make_preedit_imtext(iml_session_t * s)
02119 {
02120     int len;
02121     int i;
02122     MyDataPerSession *session_data = (MyDataPerSession *) s->specific_data;
02123     IMText *p = (IMText *) s->If->m->iml_new(s, sizeof(IMText));
02124     memset(p, 0, sizeof(IMText));
02125 
02126     p->encoding = UTF16_CODESET;
02127     len = UTFCHARLen(session_data->preedit_buf);
02128     p->text.utf_chars = (UTFCHAR *) s->If->m->iml_new(s, sizeof(UTFCHAR) * (len + 1));
02129     UTFCHARCpy(p->text.utf_chars, session_data->preedit_buf);
02130     p->char_length = len;
02131     p->feedback = create_feedback(s, p->char_length);
02132     for (i = 0; i < p->char_length; i++) {
02133         set_feedback(&p->feedback[i], get_feedback(&session_data->preedit_feedback[i]));
02134         printf("0x%x[%d %d]", p->text.utf_chars[i], get_feedback(&p->feedback[i]), get_feedback(&session_data->preedit_feedback[i]));
02135     }
02136     printf("\n");
02137     return p;
02138 }
02139 
02140 void
02141 preedit_draw(
02142     iml_session_t * s
02143 )
02144 {
02145     iml_inst *lp;
02146     iml_inst *rrv = NULL;
02147     
02148     MyDataPerSession *session_data = (MyDataPerSession *) s->specific_data;
02149     IMText *p = make_preedit_imtext(s);
02150     
02151     if (session_data->preedit_start == False) {
02152         lp = s->If->m->iml_make_preedit_start_inst(s);
02153         s->If->m->iml_link_inst_tail(&rrv, lp);
02154         session_data->preedit_start = True;
02155     }
02156 #ifdef IML_API_TEST
02157     /*
02158     * text replacement text
02159     */
02160     lp = s->If->m->iml_make_preedit_draw_with_chgpos_inst(s,
02161         p,
02162         0,
02163         s->PreEditTextInfo.text->char_length,
02164         UTFCHARLen(p->text.utf_chars));
02165 #else
02166     lp = s->If->m->iml_make_preedit_draw_inst(s, p);
02167 #endif
02168     
02169     s->If->m->iml_link_inst_tail(&rrv, lp);
02170     s->If->m->iml_execute(s, &rrv);
02171 }
02172 
02173 void
02174 iml_make_preedit_draw_with_chgpos_inst_test(iml_session_t * s)
02175 {
02176     iml_inst *lp;
02177     iml_inst *rrv = NULL;
02178     int i;
02179     UTFCHAR test_string[] = {0x30aa, 0x30f3, 0x0};
02180     
02181     /*
02182     * replacement chg_pos=1 chg_len=3 to text (len=2)
02183     */
02184     
02185     MyDataPerSession *session_data = (MyDataPerSession *) s->specific_data;
02186     IMText *p = (IMText *) s->If->m->iml_new(s, sizeof(IMText));
02187     int len = 2;
02188 
02189     memset(p, 0, sizeof(IMText));
02190     p->encoding = UTF16_CODESET;
02191     p->text.utf_chars = (UTFCHAR *) s->If->m->iml_new(s, sizeof(UTFCHAR) * (len + 1));
02192     UTFCHARCpy(p->text.utf_chars, test_string);
02193     p->char_length = len;
02194     p->feedback = create_feedback(s, p->char_length);
02195     for (i = 0; i < p->char_length; i++) {
02196         set_feedback(&p->feedback[i], IMUnderline);
02197     }
02198     lp = s->If->m->iml_make_preedit_draw_with_chgpos_inst(s,
02199         p,
02200         1,
02201         4,
02202         0);
02203     s->If->m->iml_link_inst_tail(&rrv, lp);
02204     s->If->m->iml_execute(s, &rrv);
02205     
02206     /*
02207     * sync preedit
02208     */
02209     for (i = 0; i < s->PreEditTextInfo.text->char_length; i++) {
02210         session_data->preedit_buf[i] = s->PreEditTextInfo.text->text.utf_chars[i];
02211         session_data->preedit_feedback[i] = s->PreEditTextInfo.text->feedback[i];
02212     }
02213     session_data->preedit_buf[i] = 0;
02214 }
02215 
02216 void
02217 lookup_commit(iml_session_t * s, int index)
02218 {
02219     int i;
02220     iml_inst *lp;
02221     iml_inst *rrv = NULL;
02222     MyDataPerSession *session_data = (MyDataPerSession *) s->specific_data;
02223     IMText **candidates = session_data->luc_candidates;
02224     index += session_data->luc_top;
02225     
02226     lp = s->If->m->iml_make_lookup_done_inst(s);
02227     s->If->m->iml_link_inst_tail(&rrv, lp);
02228     session_data->luc_current_candidate = 0;
02229     
02230     /* erase first */
02231     lp = s->If->m->iml_make_preedit_erase_inst(s);
02232     s->If->m->iml_link_inst_tail(&rrv, lp);
02233     
02234     lp = s->If->m->iml_make_commit_inst(s, candidates[index]);
02235     s->If->m->iml_link_inst_tail(&rrv, lp);
02236     
02237     s->If->m->iml_execute(s, &rrv);
02238     
02239     for (i = 0; i < BUFSIZE; i++) {
02240         set_feedback(&session_data->preedit_feedback[i], IMUnderline);
02241     }
02242     
02243     if (session_data->preedit_string[0]) {
02244         UTFCHARCpy(session_data->preedit_buf, session_data->preedit_string);
02245         session_data->preedit_buf[UTFCHARLen(session_data->preedit_string)] = 0;
02246         preedit_draw(s);
02247     } else {
02248         memset(session_data->preedit_buf, 0, sizeof(UTFCHAR) * BUFSIZE);
02249     }
02250     
02251     memset(session_data->preedit_string, 0, sizeof(UTFCHAR) * BUFSIZE);
02252     memset(session_data->conversion_string, 0, sizeof(UTFCHAR) * BUFSIZE);
02253     
02254     session_data->caret_pos = -1;
02255     
02256     session_data->luc_start = False;
02257     s->If->m->iml_delete2(s);
02258 }
02259 
02260 void
02261 lookup_prev(iml_session_t * s)
02262 {
02263     MyDataPerSession *session_data = (MyDataPerSession *) s->specific_data;
02264     session_data->luc_top -= session_data->luc_nchoices;
02265     session_data->luc_current_candidate = 0;
02266     if (session_data->luc_top < 0) {
02267         int p = session_data->max_candidates % session_data->luc_nchoices;
02268         session_data->luc_top = session_data->max_candidates - p;
02269     }
02270 }
02271 
02272 void
02273 lookup_next(iml_session_t * s)
02274 {
02275     MyDataPerSession *session_data = (MyDataPerSession *) s->specific_data;
02276     session_data->luc_top += session_data->luc_nchoices;
02277     session_data->luc_current_candidate = 0;
02278     if (session_data->luc_top > session_data->max_candidates) {
02279         session_data->luc_top = 0;
02280     }
02281 }
02282 
02283 void
02284 lookup_test(iml_session_t * s)
02285 {
02286     int i;
02287     int j = 0;
02288     int k = 0;
02289     iml_inst *lp;
02290     MyDataPerSession *session_data = (MyDataPerSession *) s->specific_data;
02291     IMLookupDrawCallbackStruct *draw;
02292     IMLookupStartCallbackStruct *start;
02293     int max_len = 0;
02294     IMText **candidates;
02295     IMText *current_text;
02296     IMText **labels;
02297     int len;
02298     UTFCHAR buf[BUFSIZE];
02299     
02300     /* duplicate */
02301     s->If->m->iml_delete2(s);
02302     
02303     session_data->luc_candidates = (IMText **) s->If->m->iml_new2(s, MAXCANDIDATES * sizeof(IMText));
02304     memset(session_data->luc_candidates, 0, MAXCANDIDATES * sizeof(IMText));
02305     
02306     candidates = session_data->luc_candidates;
02307     
02308     if (session_data->conversion_string[0]) {
02309         UTFCHARCpy(buf, session_data->conversion_string);
02310     } else {
02311         return;
02312     }
02313     
02314     for (i = 0; i < MAXCANDIDATES; i++) {
02315         char tmp[3];
02316         sprintf(tmp, "%d", i);
02317         candidates[i] = (IMText *) s->If->m->iml_new2(s, sizeof(IMText));
02318         memset(candidates[i], 0, sizeof(IMText));
02319         candidates[i]->encoding = UTF16_CODESET;
02320         candidates[i]->char_length = UTFCHARLen(buf) + strlen(tmp);
02321         candidates[i]->text.utf_chars = (UTFCHAR *) s->If->m->iml_new2(s,
02322             sizeof(UTFCHAR) * (candidates[i]->char_length + 1));
02323         memset(candidates[i]->text.utf_chars, 0, sizeof(UTFCHAR) * (candidates[i]->char_length + 1));
02324         UTFCHARCpy(candidates[i]->text.utf_chars, buf);
02325         if (i > 9) {
02326             candidates[i]->text.utf_chars[candidates[i]->char_length - 2] = tmp[0];
02327             candidates[i]->text.utf_chars[candidates[i]->char_length - 1] = tmp[1];
02328         } else {
02329             candidates[i]->text.utf_chars[candidates[i]->char_length - 1] = tmp[0];
02330         }
02331         candidates[i]->feedback = create_feedback2(s, candidates[i]->char_length);
02332         if (i == session_data->luc_current_candidate) {
02333             for (j = 0; j < candidates[i]->char_length; j++) {
02334                 set_feedback(&candidates[i]->feedback[j], IMReverse);
02335             }
02336         } else {
02337             for (j = 0; j < candidates[i]->char_length; j++) {
02338                 if (0) {
02339                     set_feedback(&candidates[i]->feedback[j], IMNormal);
02340                 }
02341                 set_feedback_private(&candidates[i]->feedback[j],
02342                     IMNormal,
02343                     IM_RGB_COLOR(255, 0, 0),
02344                     IM_RGB_COLOR(255, 192, 203),
02345                     -1);
02346             }
02347         }
02348     }
02349     
02350     current_text = candidates[session_data->luc_current_candidate];
02351     
02352     session_data->luc_labels = (IMText **) s->If->m->iml_new2(s, MAXCANDIDATES * sizeof(IMText));
02353     memset(session_data->luc_labels, 0, MAXCANDIDATES * sizeof(IMText));
02354     
02355     j = 0;
02356     labels = session_data->luc_labels;
02357     for (i = '1'; i <= '9'; i++, j++) {
02358         labels[j] = (IMText *) s->If->m->iml_new2(s, sizeof(IMText));
02359        memset(labels[j], 0, sizeof(IMText));
02360         labels[j]->encoding = UTF16_CODESET;
02361         labels[j]->char_length = 1;
02362         labels[j]->text.utf_chars = (UTFCHAR *) s->If->m->iml_new2(s,
02363             sizeof(UTFCHAR) * (labels[j]->char_length + 1));
02364         labels[j]->text.utf_chars[0] = (UTFCHAR) i;
02365         labels[j]->feedback = create_feedback2(s, labels[j]->char_length);
02366         
02367         for (k = 0; k < labels[j]->char_length; k++) {
02368             set_feedback_private(&labels[j]->feedback[k],
02369                 IMNormal,
02370                 IM_RGB_COLOR(0, 0, 0),
02371                 IM_RGB_COLOR(192, 192, 192),
02372                 -1);
02373         }
02374     }
02375     for (i = 'A'; i <= 'Z'; i++, j++) {
02376         labels[j] = (IMText *) s->If->m->iml_new2(s, sizeof(IMText));
02377        memset(labels[j], 0, sizeof(IMText));
02378         labels[j]->char_length = 1;
02379         labels[j]->text.utf_chars = (UTFCHAR *) s->If->m->iml_new2(s,
02380             sizeof(UTFCHAR) * (labels[j]->char_length + 1));
02381         labels[j]->text.utf_chars[0] = (UTFCHAR) i;
02382         labels[j]->feedback = create_feedback2(s, labels[j]->char_length);
02383         for (k = 0; k < labels[j]->char_length; k++) {
02384             set_feedback_private(&labels[j]->feedback[k],
02385                 IMNormal,
02386                 IM_RGB_COLOR(0, 0, 0),
02387                 IM_RGB_COLOR(192, 192, 192),
02388                 -1);
02389         }
02390     }
02391     for (i = 'a'; i <= 'z'; i++, j++) {
02392         labels[j] = (IMText *) s->If->m->iml_new2(s, sizeof(IMText));
02393        memset(labels[j], 0, sizeof(IMText));
02394         labels[j]->encoding = UTF16_CODESET;
02395         labels[j]->char_length = 1;
02396         labels[j]->text.utf_chars = (UTFCHAR *) s->If->m->iml_new2(s,
02397             sizeof(UTFCHAR) * (labels[j]->char_length + 1));
02398         labels[j]->text.utf_chars[0] = (UTFCHAR) i;
02399         labels[j]->feedback = create_feedback2(s, labels[j]->char_length);
02400         for (k = 0; k < labels[j]->char_length; k++) {
02401             set_feedback_private(&labels[j]->feedback[k],
02402                 IMNormal,
02403                 IM_RGB_COLOR(0, 0, 0),
02404                 IM_RGB_COLOR(192, 192, 192),
02405                 -1);
02406         }
02407     }
02408     labels = session_data->luc_labels;
02409     
02410     if (session_data->luc_start == False) {
02411         session_data->luc_top = 0;
02412         start = (IMLookupStartCallbackStruct *) s->If->m->iml_new(s, sizeof(IMLookupStartCallbackStruct));
02413        memset(start, 0, sizeof(IMLookupStartCallbackStruct));
02414         start->whoIsMaster = IMIsMaster;
02415         session_data->luc_type = IMIsMaster;
02416         start->IMPreference = (LayoutInfo *) s->If->m->iml_new(s, sizeof(LayoutInfo));
02417        memset(start->IMPreference, 0, sizeof(LayoutInfo));
02418         start->IMPreference->choice_per_window = 36;
02419         start->IMPreference->ncolumns = 6;
02420         start->IMPreference->nrows = 6;
02421         start->IMPreference->drawUpDirection = DrawUpHorizontally;
02422         start->IMPreference->whoOwnsLabel = IMOwnsLabel;
02423         start->CBPreference = NULL;
02424         lp = s->If->m->iml_make_lookup_start_inst(s, start);
02425         s->If->m->iml_execute(s, &lp);
02426         session_data->luc_start = True;
02427     }
02428     draw = (IMLookupDrawCallbackStruct *) s->If->m->iml_new(s, sizeof(IMLookupDrawCallbackStruct));
02429     memset(draw, 0, sizeof(IMLookupDrawCallbackStruct));
02430     draw->index_of_first_candidate = 0;
02431     draw->index_of_last_candidate = 35;
02432     draw->n_choices = draw->index_of_last_candidate - draw->index_of_first_candidate + 1;
02433     
02434 #ifdef notdef
02435     draw->title = (IMText *) NULL;
02436 #else
02437     draw->title = (IMText *) s->If->m->iml_new(s, sizeof(IMText));
02438     memset(draw->title, 0, sizeof(IMText));
02439     draw->title->encoding = UTF16_CODESET;
02440     draw->title->char_length = UTFCHARLen(title_string);
02441     draw->title->text.utf_chars = (UTFCHAR *) s->If->m->iml_new(s, sizeof(IMText) * (draw->title->char_length + 1));
02442     UTFCHARCpy(draw->title->text.utf_chars, title_string);
02443     draw->title->feedback = create_feedback(s, draw->title->char_length);
02444 #endif
02445     
02446     draw->choices = (IMChoiceObject *) s->If->m->iml_new(s, draw->n_choices * sizeof(IMChoiceObject));
02447     memset(draw->choices, 0, draw->n_choices * sizeof(IMChoiceObject));
02448     
02449     for (i = 0; i < draw->n_choices; i++) {
02450         IMText *vt;         /* for value */
02451         IMText *lt;         /* for label */
02452         vt = draw->choices[i].value = candidates[i + session_data->luc_top];
02453         lt = draw->choices[i].label = labels[i];
02454         
02455         printf("candidates[%d]=%x\n", i + session_data->luc_top,
02456             candidates[i + session_data->luc_top]);
02457         
02458         if (max_len < vt->char_length)
02459             max_len = vt->char_length;
02460         
02461         if (i + session_data->luc_top == session_data->max_candidates) {
02462             draw->index_of_first_candidate = 0;
02463             draw->index_of_last_candidate = i;
02464             draw->n_choices = i + 1;
02465             break;
02466         }
02467     }
02468     draw->max_len = max_len;
02469     draw->max_len = 20;
02470     draw->index_of_current_candidate = session_data->luc_current_candidate;
02471     
02472     printf("session_data->luc_top=%x\n", session_data->luc_top);
02473     
02474     printf("draw->index_of_first_candidate=%x\n", draw->index_of_first_candidate);
02475     printf("draw->index_of_last_candidate=%x\n", draw->index_of_last_candidate);
02476     printf("draw->n_choices=%x\n", draw->n_choices);
02477     printf("draw->choices=%x\n", draw->choices);
02478     printf("draw->choices->label=%x\n", draw->choices->label);
02479     printf("draw->max_len=%x\n", max_len);
02480     printf("draw->index_of_current_candidate=%x\n", session_data->luc_current_candidate);
02481     
02482     lp = s->If->m->iml_make_lookup_draw_inst(s, draw);
02483     s->If->m->iml_execute(s, &lp);
02484     
02485     {
02486         int last_reverse = 0;
02487         UTFCHAR tmp[BUFSIZE];
02488         UTFCHAR tmp2[BUFSIZE];
02489         len = UTFCHARLen(session_data->preedit_buf);
02490         
02491         j = 0;
02492         UTFCHARCpy(tmp, candidates[session_data->luc_top + session_data->luc_current_candidate]->text.utf_chars);
02493         
02494         printf("##\n");
02495         preedit_buf_print(s);
02496         printf("##\n");
02497         
02498         for (i = 0; i < len; i++) {
02499             printf("%d %x\n", get_feedback(&session_data->preedit_feedback[i]));
02500             if (get_feedback(&session_data->preedit_feedback[i]) == IMUnderline) {
02501                 last_reverse = 1;
02502             }
02503             if (last_reverse) {
02504                 tmp2[j] = session_data->preedit_buf[i];
02505                 printf("U %d = %x\n", j, tmp2[j]);
02506                 j++;
02507             }
02508         }
02509         tmp2[j] = 0;
02510         printf("U %d = %x\n", j, tmp2[j]);
02511         
02512         UTFCHARCat(session_data->preedit_buf, tmp, tmp2);
02513         
02514         printf("##\n");
02515         preedit_buf_print(s);
02516         printf("##\n");
02517         
02518         for (i = 0; i < UTFCHARLen(tmp); i++) {
02519             set_feedback(&session_data->preedit_feedback[i], IMReverse);
02520         }
02521         for (i = UTFCHARLen(tmp); i < UTFCHARLen(session_data->preedit_buf); i++) {
02522             set_feedback(&session_data->preedit_feedback[i], IMUnderline);
02523         }
02524         preedit_draw(s);
02525     }
02526 }
02527 
02528 void
02529 receive_aux(
02530     iml_session_t * s,
02531     IMAuxDrawCallbackStruct * aux
02532 )
02533 {
02534     IMText *lts, *lt;
02535     int i, j;
02536        iml_inst *lp;
02537 
02538     MyDataPerDesktop *desktop_data = (MyDataPerDesktop *) s->desktop->specific_data;
02539     printf("Received AUX data\n");
02540     
02541     printf("\taux_name=[%s]\n", aux->aux_name);
02542     printf("\tcount_integer_values=[%d]\n", aux->count_integer_values);
02543     printf("\tcount_string_values=[%d]\n", aux->count_string_values);
02544     
02545     printf("\t** INT[] **\n");
02546     for (i = 0; i < aux->count_integer_values; i++) {
02547         printf("\t%3d:0x%08x\n", i, aux->integer_values[i]);
02548     }
02549     printf("\t** STR[] **\n");
02550     lts = aux->string_values;
02551     for (i = 0, lt = lts; i < aux->count_string_values; i++, lt++) {
02552         printf("\t%3d:[%d]", i, lt->char_length);
02553         for (j = 0; j < lt->char_length; j++) {
02554             printf("[%x]", lt->text.utf_chars[j]);
02555         }
02556         printf("\n");
02557     }
02558     
02559     if (!strcmp(aux->aux_name, class_names[SAMPLE_AUX_PANEL])) {
02560         if (aux->count_string_values == 1 && aux->integer_values[0] == 1 &&
02561           UTFCHARCmp2(aux->string_values[0].text.utf_chars, "DICT", 4)) {
02562             if (desktop_data->aux_start[SAMPLE_AUX_DICT] == False) {
02563                 aux_start(desktop_data->auxproxy_session, SAMPLE_AUX_DICT);
02564             } else {
02565                 aux_draw(desktop_data->auxproxy_session, SAMPLE_AUX_DICT, 0, NULL, 0, NULL);
02566             }
02567         }
02568     } else if (!strcmp(aux->aux_name, class_names[SAMPLE_AUX_DICT])) {
02569         if (aux->count_string_values == 2) {
02570             UTFCHAR *from, *to;
02571             IMText *fromt, *tot;
02572             fromt = &aux->string_values[0];
02573             tot = &aux->string_values[1];
02574             from = s->If->m->iml_new(s, sizeof(UTFCHAR) * (fromt->char_length + 1));
02575             to = s->If->m->iml_new(s, sizeof(UTFCHAR) * (tot->char_length + 1));
02576             memset(from, 0, sizeof(UTFCHAR) * (fromt->char_length) + 1);
02577             memset(to, 0, sizeof(UTFCHAR) * (tot->char_length) + 1);
02578             
02579             memcpy(from, fromt->text.utf_chars, sizeof(UTFCHAR) * fromt->char_length);
02580             memcpy(to, tot->text.utf_chars, sizeof(UTFCHAR) * tot->char_length);
02581             add_dict(s->desktop->specific_data, from, to);
02582 
02583            lp = s->If->m->iml_make_preedit_draw_inst(s, make_imtext(s, add_string));
02584             s->If->m->iml_execute(s, &lp);
02585         } else if (aux->count_integer_values == 1) {
02586             if (aux->integer_values[0] == 0) {
02587                 /*
02588                 * aux_done(s, SAMPLE_AUX_DICT);
02589                 */
02590             }
02591         }
02592     }
02593 #ifdef notdef
02594     if (aux->integer_values[SAMPLE_AUX_PANEL] == 1 &&
02595       aux->count_string_values == 1 &&
02596       UTFCHARCmp2(aux->string_values[0].text.utf_chars, "DICT", aux->string_values[0].char_length)) {
02597         aux_start(desktop_data->auxproxy_session, SAMPLE_AUX_DICT);
02598     } else {
02599         int aux_int_data[] = {1};
02600         aux_draw(desktop_data->auxproxy_session, SAMPLE_AUX_DICT, 1, aux_int_data, 0, NULL);
02601     }
02602 #endif
02603 }
02604 
02605 void
02606 aux_start(
02607     iml_session_t * s,
02608     int class_name_id
02609 )
02610 {
02611     MyDataPerDesktop *desktop_data = (MyDataPerDesktop *) s->desktop->specific_data;
02612     if (desktop_data->aux_start[class_name_id] == False) {
02613         iml_inst *lp;
02614         IMAuxStartCallbackStruct *aux = (IMAuxStartCallbackStruct *) s->If->m->iml_new(s, sizeof(IMAuxStartCallbackStruct));
02615        memset(aux, 0, sizeof(IMAuxStartCallbackStruct));
02616         aux->aux_name = class_names[class_name_id];
02617         lp = s->If->m->iml_make_aux_start_inst(s, aux);
02618         s->If->m->iml_execute(s, &lp);
02619         printf("Starting AUX [%s]\n", class_names[class_name_id]);
02620         desktop_data->aux_start[class_name_id] = True;
02621     } else {
02622         printf("AUX[%s] is already started.\n", class_names[class_name_id]);
02623     }
02624 }
02625 
02626 void
02627 aux_done(
02628     iml_session_t * s,
02629     int class_name_id
02630 )
02631 {
02632     MyDataPerDesktop *desktop_data = (MyDataPerDesktop *) s->desktop->specific_data;
02633     if (desktop_data->aux_start[class_name_id] == True) {
02634         iml_inst *lp;
02635         IMAuxDoneCallbackStruct *aux = (IMAuxDoneCallbackStruct *) s->If->m->iml_new(s, sizeof(IMAuxDoneCallbackStruct));
02636        memset(aux, 0, sizeof(IMAuxDoneCallbackStruct));
02637         aux->aux_name = class_names[class_name_id];
02638         lp = s->If->m->iml_make_aux_done_inst(s, aux);
02639         s->If->m->iml_execute(s, &lp);
02640         printf("Closing AUX\n");
02641         desktop_data->aux_start[class_name_id] = False;
02642     } else {
02643         printf("AUX is already done.\n");
02644     }
02645 }
02646 
02647 UTFCHAR sample_string[] = {0x53d7, 0x3051, 0x53d6, 0x3063, 0x305f, 0x305e, 0x30fc, 0};
02648 
02649 void
02650 aux_draw(
02651     iml_session_t * s,
02652     int class_name_id,
02653     int count_integers,
02654     int *integers,
02655     int count_strings,
02656     UTFCHAR ** strings
02657 )
02658 {
02659     iml_inst *lp;
02660     int i, j;
02661     int len = 7;
02662     IMText *lts, *lt;
02663     IMAuxDrawCallbackStruct *aux;
02664     MyDataPerDesktop *desktop_data;
02665 
02666     if (!s) return;
02667 
02668     desktop_data = (MyDataPerDesktop *) s->desktop->specific_data;
02669     
02670     if (desktop_data->aux_start[class_name_id] == False) {
02671         printf("AUX is not started.\n");
02672         return;
02673     }
02674     aux = (IMAuxDrawCallbackStruct *) s->If->m->iml_new(s, sizeof(IMAuxDrawCallbackStruct));
02675     memset(aux, 0, sizeof(IMAuxDrawCallbackStruct));
02676     
02677     aux->aux_name = class_names[class_name_id];
02678     
02679     aux->count_integer_values = count_integers;
02680     if (aux->count_integer_values) {
02681         aux->integer_values = (int *) s->If->m->iml_new(s, sizeof(int) * aux->count_integer_values);
02682         for (i = 0; i < aux->count_integer_values; i++) {
02683             aux->integer_values[i] = integers[i];
02684         }
02685     }
02686     aux->count_string_values = count_strings;
02687     if (aux->count_string_values) {
02688         aux->string_values = lts = (IMText *)
02689         s->If->m->iml_new(s, sizeof(IMText) * aux->count_string_values);
02690         memset(aux->string_values, 0, sizeof(IMText) * aux->count_string_values);
02691         aux->string_values->encoding = UTF16_CODESET;
02692         
02693         for (i = 0, lt = lts; i < aux->count_string_values; i++, lt++) {
02694             len = UTFCHARLen(strings[i]);
02695             lt->text.utf_chars = (UTFCHAR *) s->If->m->iml_new(s, sizeof(UTFCHAR) * (len + 1));
02696             lt->char_length = len + 1;
02697             UTFCHARCpy(lt->text.utf_chars, strings[i]);
02698         }
02699     }
02700     lp = s->If->m->iml_make_aux_draw_inst(s, aux);
02701     s->If->m->iml_execute(s, &lp);
02702 }
02703 
02704 /* conversion table for predefined dictionary */
02705 
02706 UTFCHAR name1_from[] = {0x3044, 0x3057, 0x3080, 0x3089, 0};
02707 UTFCHAR name1_to[] = {0x77f3, 0x6751, 0};
02708 UTFCHAR name2_from[] = {0x304b, 0x305f, 0x304b, 0x3044, 0};
02709 UTFCHAR name2_to[] = {0x7247, 0x8c9d, 0};
02710 UTFCHAR name3_from[] = {0x305f, 0x3058, 0x307e, 0};
02711 UTFCHAR name3_to[] = {0x7530, 0x5cf6, 0};
02712 UTFCHAR name4_from[] = {0x304f, 0x307e, 0x30fc, 0};
02713 UTFCHAR name4_to[] = {0x30af, 0x30de, 0x30fc, 0};
02714 UTFCHAR name5_from[] = {0x307e, 0x3064, 0x305f, 0x304b, 0x3053, 0};
02715 UTFCHAR name5_to[] = {0x677e, 0x305f, 0x304b, 0x5b50, 0};
02716 UTFCHAR name6_from[] = {0x3064, 0x304e, 0x306e, 0x305b, 0x3060, 0x3044, 0};
02717 UTFCHAR name6_to[] = {0x6b21, 0x306e, 0x4e16, 0x4ee3, 0};
02718 UTFCHAR name7_from[] = {0x3072, 0x304d, 0x3064, 0x304e, 0};
02719 UTFCHAR name7_to[] = {0x5f15, 0x304d, 0x7d99, 0x304e, 0};
02720 
02721 henkan_table3 htable3[] = {
02722     {name1_from, name1_to},
02723     {name2_from, name2_to},
02724     {name3_from, name3_to},
02725     {name4_from, name4_to},
02726     {name5_from, name5_to},
02727     {name6_from, name6_to},
02728     {name7_from, name7_to},
02729     {0, 0},
02730 };
02731 
02732 /* add word */
02733 
02734 void
02735 add_dict(
02736     MyDataPerDesktop * desktop_data,
02737     UTFCHAR * from,
02738     UTFCHAR * to
02739 )
02740 {
02741     henkan_table3 *p = (henkan_table3 *) calloc(1, sizeof(henkan_table3));
02742     int from_len = UTFCHARLen(from);
02743     int to_len = UTFCHARLen(to);
02744     p->from = (UTFCHAR *) calloc(1, sizeof(UTFCHAR) * (from_len + 1));
02745     p->to = (UTFCHAR *) calloc(1, sizeof(UTFCHAR) * (to_len + 1));
02746     
02747     UTFCHARCpy(p->from, from);
02748     UTFCHARCpy(p->to, to);
02749     
02750     desktop_data->userdict[desktop_data->wordcount] = p;
02751     desktop_data->wordcount++;
02752 }
02753 
02754 /* do conversion */
02755 
02756 Bool
02757 do_convert(
02758     iml_session_t * s
02759 )
02760 {
02761     int i, j;
02762     MyDataPerSession *session_data = (MyDataPerSession *) s->specific_data;
02763     MyDataPerDesktop *desktop_data = (MyDataPerDesktop *) s->desktop->specific_data;
02764     
02765     for (i = 0; i < desktop_data->wordcount; i++) {
02766         henkan_table3 *p = desktop_data->userdict[i];
02767         if (UTFCHARCmp(session_data->preedit_buf, p->from) == True) {
02768             UTFCHARCpy(session_data->preedit_buf, p->to);
02769             for (j = 0; j < BUFSIZE; j++) {
02770                 set_feedback(&session_data->preedit_feedback[j], IMReverse);
02771             }
02772             preedit_draw(s);
02773             return True;
02774         }
02775     }
02776     
02777     for (i = 0; htable3[i].from; i++) {
02778         if (UTFCHARCmp(session_data->preedit_buf, htable3[i].from) == True) {
02779             UTFCHARCpy(session_data->preedit_buf, htable3[i].to);
02780             for (j = 0; j < BUFSIZE; j++) {
02781                 set_feedback(&session_data->preedit_feedback[j], IMReverse);
02782             }
02783             preedit_draw(s);
02784             return True;
02785         }
02786     }
02787     return False;
02788 }
02789 
02790 IMFeedbackList *
02791 create_feedback_with_color(
02792     iml_session_t * s,
02793     int size,
02794     int normalfeedback,
02795     int fg,
02796     int bg
02797 )
02798 {
02799     int i;
02800     IMFeedbackList *feedback, *fbl;
02801     feedback = (IMFeedbackList *) create_feedback(s, size);
02802     for (i = 0; i < size; i++) {
02803         IMFeedbackList *fbl = &feedback[i];
02804         set_feedback_private(fbl, normalfeedback, fg, bg, -1);
02805     }
02806     
02807     return feedback;
02808 }
02809 
02810 IMFeedbackList *
02811 create_feedback2(
02812     iml_session_t * s,
02813     int size
02814 )
02815 {
02816     int i;
02817     IMFeedbackList *feedback, *fbl;
02818     IMFeedback *fb;
02819     
02820     if (s) {
02821         feedback = (IMFeedbackList *) s->If->m->iml_new2(s, sizeof(IMFeedbackList) * size);
02822     } else {
02823         feedback = (IMFeedbackList *) calloc(1, sizeof(IMFeedbackList) * size);
02824     }
02825     for (i = 0; i < size; i++) {
02826         IMFeedbackList *fbl = &feedback[i];
02827         fbl->count_feedbacks = 1;
02828         if (s) {
02829             fb = fbl->feedbacks = (IMFeedback *) s->If->m->iml_new2(s, sizeof(IMFeedback) * 4);
02830         } else {
02831             fb = fbl->feedbacks = (IMFeedback *) calloc(1, sizeof(IMFeedback) * 4);
02832         }
02833         memset(fbl->feedbacks, 0, sizeof(IMFeedback) * 4);
02834     }
02835     return feedback;
02836 }
02837 
02838 IMFeedbackList *
02839 create_feedback(
02840     iml_session_t * s,
02841     int size
02842 )
02843 {
02844     int i;
02845     IMFeedbackList *feedback, *fbl;
02846     IMFeedback *fb;
02847     
02848     if (s) {
02849         feedback = (IMFeedbackList *) s->If->m->iml_new(s, sizeof(IMFeedbackList) * size);
02850     } else {
02851         feedback = (IMFeedbackList *) calloc(1, sizeof(IMFeedbackList) * size);
02852     }
02853     for (i = 0; i < size; i++) {
02854         IMFeedbackList *fbl = &feedback[i];
02855         fbl->count_feedbacks = 1;
02856         if (s) {
02857             fb = fbl->feedbacks = (IMFeedback *) s->If->m->iml_new(s, sizeof(IMFeedback) * 4);
02858         } else {
02859             fb = fbl->feedbacks = (IMFeedback *) calloc(1, sizeof(IMFeedback) * 4);
02860         }
02861         memset(fbl->feedbacks, 0, sizeof(IMFeedback) * 4);
02862     }
02863     return feedback;
02864 }
02865 
02866 int
02867 get_feedback(
02868     IMFeedbackList * fbl
02869 )
02870 {
02871     /* returns IM_DECORATION_FEEDBACK */
02872     IMFeedback *fb = &fbl->feedbacks[0];
02873     return IM_FEEDBACK_VALUE(fb);
02874 }
02875 
02876 void
02877 set_feedback_private(
02878     IMFeedbackList * fbl,
02879     int normalfeedback,
02880     int fg,
02881     int bg,
02882     int underline
02883 )
02884 {
02885     int count = 0;
02886     IMFeedback *fb;
02887     
02888     fb = &fbl->feedbacks[count];
02889     IM_FEEDBACK_TYPE(fb) = IM_DECORATION_FEEDBACK;
02890     IM_FEEDBACK_VALUE(fb) = normalfeedback;
02891     count++;
02892     
02893 #ifdef USE_COLOR_FEEDBACK
02894 
02895     if (fg != -1) {
02896         fb = &fbl->feedbacks[count];
02897         IM_FEEDBACK_TYPE(fb) = IM_FOREGROUND_RGB_FEEDBACK;
02898         IM_FEEDBACK_VALUE(fb) = fg;
02899         count++;
02900     }
02901     if (bg != -1) {
02902         fb = &fbl->feedbacks[count];
02903         IM_FEEDBACK_TYPE(fb) = IM_BACKGROUND_RGB_FEEDBACK;
02904         IM_FEEDBACK_VALUE(fb) = bg;
02905         count++;
02906     }
02907     if (underline != -1) {
02908         fb = &fbl->feedbacks[count];
02909         IM_FEEDBACK_TYPE(fb) = IM_UNDERLINE_RGB_FEEDBACK;
02910         IM_FEEDBACK_VALUE(fb) = underline;
02911         count++;
02912     }
02913 
02914 #endif
02915     IM_FEEDBACK_COUNT(fbl) = count;
02916 }
02917 
02918 void
02919 set_feedback(
02920     IMFeedbackList * fbl,
02921     int normalfeedback
02922 )
02923 {
02924     
02925     if (normalfeedback == IMUnderline) {
02926         set_feedback_private(fbl,
02927             IMUnderline,
02928             IM_RGB_COLOR(0, 0, 255),             /* FG: blue */
02929             IM_RGB_COLOR(255, 255, 255),  /* BG: white */
02930             IM_RGB_COLOR(0, 0, 255));
02931     } else if (normalfeedback == IMReverse) {
02932         set_feedback_private(fbl,
02933             IMReverse,
02934             IM_RGB_COLOR(255, 255, 255),  /* FG: white */
02935             IM_RGB_COLOR(0, 0, 255),             /* BG: blue */
02936             -1);
02937     } else {
02938         set_feedback_private(fbl,
02939             IMNormal,
02940             -1,
02941             -1,
02942             -1);
02943     }
02944 }
02945 
02946 void
02947 SetFeedback(
02948     iml_session_t * s,
02949     IMText * text
02950 )
02951 {
02952     int i;
02953     IMFeedbackList *fbl;
02954     IMFeedback *fb;
02955     int size;
02956     
02957     size = text->char_length;
02958     text->feedback = (IMFeedbackList *) s->If->m->iml_new(s,
02959                             sizeof(IMFeedbackList) * size);
02960     
02961     /* set color for each character */
02962     for (i = 0; i < size; i++) {
02963         fbl = &text->feedback[i];
02964         fbl->count_feedbacks = 3;  /* IM_DECORATION_FEEDBACK,
02965                                     * IM_FOREGROUND_RGB_FEEDBACK,
02966                                     * IM_BACKGROUND_RGB_FEEDBACK */
02967 
02968         fbl->feedbacks = (IMFeedback *) s->If->m->iml_new(s,
02969                             sizeof(IMFeedback) * fbl->count_feedbacks);
02970         
02971         /*
02972         * normal decolation, IM_DECORATION_FEEDBACK is required in
02973         * the first element
02974         */
02975         fb = &fbl->feedbacks[0];
02976         IM_FEEDBACK_TYPE(fb) = IM_DECORATION_FEEDBACK;
02977         IM_FEEDBACK_VALUE(fb) = IMNormal;
02978         
02979         /* foreground is blue */
02980         fb = &fbl->feedbacks[1];
02981         IM_FEEDBACK_TYPE(fb) = IM_FOREGROUND_RGB_FEEDBACK;
02982         IM_FEEDBACK_VALUE(fb) = IM_RGB_COLOR(0, 0, 255);
02983         
02984         /* background is blue */
02985         fb = &fbl->feedbacks[2];
02986         IM_FEEDBACK_TYPE(fb) = IM_BACKGROUND_RGB_FEEDBACK;
02987         IM_FEEDBACK_VALUE(fb) = IM_RGB_COLOR(255, 255, 255);
02988     }
02989 }