Back to index

im-sdk  12.3.91
sampleja3.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 #include <stdio.h>
00043 #include <stdlib.h>
00044 #include <string.h>
00045 #include <sys/types.h>
00046 
00047 #include "SunIM.h"
00048 
00049 #include "sampleja3_xaux.h"
00050 
00051 /*
00052  * define If method prototype
00053  */
00054 Bool if_sampleja3_OpenIF(iml_if_t *);
00055 Bool if_sampleja3_CloseIF(iml_if_t *);
00056 Bool if_sampleja3_GetIFValues(iml_if_t *, IMArgList, int);
00057 Bool if_sampleja3_SetIFValues(iml_if_t *, IMArgList, int);
00058 Bool if_sampleja3_OpenDesktop(iml_desktop_t *, IMArgList, int);
00059 Bool if_sampleja3_CloseDesktop(iml_desktop_t *);
00060 Bool if_sampleja3_CreateSC(iml_session_t *, IMArgList, int);
00061 Bool if_sampleja3_DestroySC(iml_session_t *);
00062 Bool if_sampleja3_GetSCValues(iml_session_t *, IMArgList, int);
00063 Bool if_sampleja3_SetSCValues(iml_session_t *, IMArgList, int);
00064 IMText *if_sampleja3_ResetSC(iml_session_t *);
00065 void if_sampleja3_SetSCFocus(iml_session_t *);
00066 void if_sampleja3_UnsetSCFocus(iml_session_t *);
00067 void if_sampleja3_SendEvent(iml_session_t *, IMInputEvent * ev);
00068 
00069 /*
00070  * define if_methods_t
00071  */
00072 static if_methods_t if_methods = {
00073     if_sampleja3_OpenIF,
00074     if_sampleja3_CloseIF,
00075     if_sampleja3_GetIFValues,
00076     if_sampleja3_SetIFValues,
00077     if_sampleja3_OpenDesktop,
00078     if_sampleja3_CloseDesktop,
00079     if_sampleja3_CreateSC,
00080     if_sampleja3_DestroySC,
00081     if_sampleja3_GetSCValues,
00082     if_sampleja3_SetSCValues,
00083     if_sampleja3_ResetSC,
00084     if_sampleja3_SetSCFocus,
00085     if_sampleja3_UnsetSCFocus,
00086     if_sampleja3_SendEvent
00087 };
00088 
00089 UTFCHAR lename_string[] = {'s', 'a', 'm', 'p', 'l', 'e', 'j', 'a', '3', 0};
00090 UTFCHAR jahrn_string[] = {0x65e5, 0x672c, 0x8a9e, 0};
00091 static IMLEName lename = {"sampleja3", lename_string};
00092 static IMLocale locales[] = {{"ja", jahrn_string}, NULL};
00093 
00094 static UTFCHAR AuxName[] = {'s', 'a', 'm', 'p', 'l', 'e', 'j', 'a', '3'};
00095 
00096 void sampleja3_conversion_on(iml_session_t *);
00097 void sampleja3_conversion_off(iml_session_t *);
00098 void sampleja3_commit_string(iml_session_t *, UTFCHAR *);
00099 
00100 IMInputEvent *modify_event(iml_session_t * s, IMInputEvent * ev);
00101 void aux_start(iml_session_t * s, char *class_name);
00102 void aux_done(iml_session_t * s, char *class_name);
00103 void aux_draw(iml_session_t * s, char *class_name, int count_integers, int *integers, int count_strings, UTFCHAR ** strings);
00104 void aux_draw2(iml_session_t * s, char *class_name, int count_integers, int *integers, int count_strings, IMText * texts);
00105 void sampleja3_receive_aux(iml_session_t * s, IMAuxDrawCallbackStruct * aux);
00106 IMText *make_imtext(iml_session_t * s, UTFCHAR * p);
00107 IMFeedbackList *create_feedback(iml_session_t * s, int size);
00108 
00109 static IMObjectDescriptorStruct *objects = 0;
00110 
00111 typedef struct Sampleja3SessionPrivate_ {
00112     int lookup_current_candidate;
00113 }   Sampleja3SessionPrivate;
00114 
00115 typedef struct Sampleja3DesktopPrivate_ {
00116     iml_session_t *root_session;
00117     iml_session_t *luc_session;
00118 }   Sampleja3DesktopPrivate;
00119 
00120 static char *class_names[] = {
00121     "com.sun.sampleja3.PaletteAux",
00122     "com.sun.sampleja3.LookupAux"
00123 };
00124 
00125 void
00126 if_GetIfInfo(
00127             IMArgList args,
00128             int num_args
00129 )
00130 {
00131     int i;
00132     for (i = 0; i < num_args; i++, args++) {
00133        switch (args->id) {
00134        case IF_VERSION:
00135            args->value = (IMArgVal) "1.2";
00136            break;
00137        case IF_METHOD_TABLE:
00138            args->value = (IMArgVal) & if_methods;
00139            break;
00140        case IF_LE_NAME:
00141            args->value = (IMArgVal) & lename;
00142            break;
00143        case IF_SUPPORTED_LOCALES:
00144            args->value = (IMArgVal) & locales;
00145            break;
00146        case IF_SUPPORTED_OBJECTS:
00147            if (!objects) {
00148                int obj_id = 0;
00149               objects = (IMObjectDescriptorStruct *)
00150                   calloc(3, sizeof(IMObjectDescriptorStruct));
00151 
00152               objects[obj_id].leid = "sampleja3";
00153               objects[obj_id].type = IM_DOWNLOADINGOBJECT_BINGUI_TYPE;
00154               objects[obj_id].name = AuxName;
00155               objects[obj_id].name_length = 9;
00156               objects[obj_id].domain = "com.sun";
00157               objects[obj_id].scope = "sampleja3";
00158               if (getenv("USE_GTK")) {
00159                 objects[obj_id].path = "sampleja3/xaux/gtk/xaux.so";
00160                } else {
00161                 objects[obj_id].path = "sampleja3/xaux/motif/xaux.so";
00162                }
00163               objects[obj_id].signature = "";
00164 
00165               obj_id++;
00166 
00167 #ifdef IF_SUPPORT_JAVA
00168               objects[obj_id].leid = "sampleja3";
00169               objects[obj_id].type = IM_DOWNLOADINGOBJECT_JARGUI_TYPE;
00170               objects[obj_id].name = AuxName;
00171               objects[obj_id].name_length = 9;
00172               objects[obj_id].domain = "com.sun";
00173               objects[obj_id].scope = "sampleja3";
00174               objects[obj_id].path = IIIMLEDIR "/sampleja3/aux.jar";
00175               objects[obj_id].signature = "";
00176               objects[obj_id].class_names = class_names;
00177               objects[obj_id].count_names = 1;
00178 #endif /* IF_SUPPORT_JAVA */
00179            }
00180            args->value = (IMArgVal) objects;
00181            break;
00182        case IF_NEED_THREAD_LOCK:
00183            args->value = (IMArgVal) True;
00184            break;
00185        default:
00186            break;
00187        }
00188     }
00189 }
00190 
00191 Bool
00192 if_sampleja3_OpenIF(
00193               iml_if_t * If
00194 )
00195 {
00196     return True;
00197 }
00198 
00199 Bool
00200 if_sampleja3_CloseIF(
00201               iml_if_t * If
00202 )
00203 {
00204     return True;
00205 }
00206 
00207 Bool
00208 if_sampleja3_GetIFValues(
00209                   iml_if_t * If,
00210                   IMArgList args,
00211                   int num_args
00212 )
00213 {
00214     int i;
00215     return True;
00216 }
00217 
00218 Bool
00219 if_sampleja3_SetIFValues(
00220                   iml_if_t * If,
00221                   IMArgList args,
00222                   int num_args
00223 )
00224 {
00225     return True;
00226 }
00227 
00228 Bool
00229 if_sampleja3_OpenDesktop(
00230                   iml_desktop_t * desktop,
00231                   IMArgList args,
00232                   int num_args
00233 )
00234 {
00235     Sampleja3DesktopPrivate *dp = (Sampleja3DesktopPrivate *) calloc(1, sizeof(Sampleja3DesktopPrivate));
00236     desktop->specific_data = (Sampleja3DesktopPrivate *) dp;
00237     return True;
00238 }
00239 
00240 Bool
00241 if_sampleja3_CloseDesktop(
00242                    iml_desktop_t * desktop
00243 )
00244 {
00245     Sampleja3DesktopPrivate *dp = (Sampleja3DesktopPrivate *) desktop->specific_data;
00246     free(dp);
00247     return True;
00248 }
00249 
00250 Bool
00251 if_sampleja3_CreateSC(
00252                iml_session_t * s,
00253                IMArgList args,
00254                int num_args
00255 )
00256 {
00257     Sampleja3SessionPrivate *p = (Sampleja3SessionPrivate *) calloc(1, sizeof(Sampleja3SessionPrivate));
00258     s->specific_data = (void *) p;
00259     return True;
00260 }
00261 
00262 Bool
00263 if_sampleja3_DestroySC(
00264                 iml_session_t * s
00265 )
00266 {
00267     Sampleja3SessionPrivate *sp = (Sampleja3SessionPrivate *) s->specific_data;
00268     free(sp);
00269     return True;
00270 }
00271 
00272 Bool
00273 if_sampleja3_GetSCValues(
00274                   iml_session_t * s,
00275                   IMArgList args,
00276                   int num_args
00277 )
00278 {
00279     return True;
00280 }
00281 
00282 Bool
00283 if_sampleja3_SetSCValues(
00284                   iml_session_t * s,
00285                   IMArgList args,
00286                   int num_args
00287 )
00288 {
00289     int i;
00290     IMArg *p = args;
00291     Sampleja3SessionPrivate *sp = (Sampleja3SessionPrivate *) s->specific_data;
00292 
00293     for (i = 0; i < num_args; i++, p++) {
00294        switch (p->id) {
00295        case SC_TRIGGER_ON_NOTIFY:
00296            sampleja3_conversion_on(s);
00297            break;
00298        case SC_TRIGGER_OFF_NOTIFY:
00299            sampleja3_conversion_off(s);
00300            break;
00301        case SC_REALIZE:
00302            if (s->desktop->session_count == 1) {
00303               Sampleja3DesktopPrivate *dp = (Sampleja3DesktopPrivate *) s->desktop->specific_data;
00304               dp->root_session = s;
00305 
00306               aux_start(s, AUX_PALETTE_CLASS_NAME);
00307               aux_start(s, AUX_LUC_CLASS_NAME);
00308            }
00309            sampleja3_conversion_off(s);
00310            break;
00311 
00312        case SC_CLIENT_LOCALE:
00313          if (p->value) printf("SC_CLIENT_LOCALE: %s\n", p->value);
00314          break;
00315        case SC_CLIENT_INPUT_METHOD_NAME:
00316          if (p->value) printf("SC_CLIENT_INPUT_METHOD_NAME: %s\n", p->value);
00317          break;
00318        case SC_CLIENT_CHARACTER_SUBSETS:
00319          if (p->value) {
00320              int *pi = (int*) p->value;
00321              printf("SC_CLIENT_CHARACTER_SUBSETS:");
00322              for (; *pi; pi++) {
00323                 printf("%d ", *pi);
00324              }
00325              printf("\n");
00326          }
00327          break;
00328                      
00329        default:
00330            break;
00331        }
00332     }
00333     return True;
00334 }
00335 
00336 IMText *
00337 if_sampleja3_ResetSC(
00338               iml_session_t * s
00339 )
00340 {
00341     return (IMText *) NULL;
00342 }
00343 
00344 void
00345 if_sampleja3_SetSCFocus(
00346                  iml_session_t * s
00347 )
00348 {
00349 }
00350 
00351 void
00352 if_sampleja3_UnsetSCFocus(
00353                    iml_session_t * s
00354 )
00355 {
00356 }
00357 
00358 void
00359 if_sampleja3_SendEvent(
00360                 iml_session_t * s,
00361                 IMInputEvent * ev_
00362 )
00363 {
00364     Sampleja3DesktopPrivate *dp = (Sampleja3DesktopPrivate *) s->desktop->specific_data;
00365 
00366     IMInputEvent *ev = modify_event(s, ev_);
00367     if (ev->type == IM_EventKeyList) {
00368        IMKeyEventStruct *key = (IMKeyEventStruct *) ((IMKeyListEvent *) ev)->keylist;
00369        sampleja3_receive_keyevent(s, key);
00370     } else if (ev->type == IM_EventAux) {
00371        IMAuxDrawCallbackStruct *aux_data = ((IMAuxEvent *) ev)->aux;
00372        sampleja3_receive_aux(s, aux_data);
00373         {
00374           int int_values[1];
00375           int_values[0] = SAMPLEJA3_AUXPALETTE_HELPSTART;
00376           printf("Help Start\n");
00377           aux_draw(s,
00378                AUX_PALETTE_CLASS_NAME,
00379                1, int_values,
00380                0, 0);
00381         }
00382     }
00383 }
00384 
00385 static UTFCHAR luc_string1[] = {0x304b, 0x3093, 0x3058, 0};
00386 static UTFCHAR luc_string2[] = {0x611f, 0x3058, 0};
00387 static UTFCHAR luc_string3[] = {0x6f22, 0x5b57, 0};
00388 static UTFCHAR luc_string4[] = {0x76e3, 0x4e8b, 0};
00389 static UTFCHAR luc_string5[] = {0x5b8c, 0x6cbb, 0};
00390 
00391 static UTFCHAR *LUC_CANDIDATES[] = {
00392     luc_string1,
00393     luc_string2,
00394     luc_string3,
00395     luc_string4,
00396 luc_string5};
00397 
00398 #define       NUM_CANDIDATES       5
00399 
00400 /* Handle KeyEvent */
00401 
00402 sampleja3_receive_keyevent(
00403                     iml_session_t * s,
00404                     IMKeyEventStruct * key
00405 )
00406 {
00407     Sampleja3DesktopPrivate *dp = (Sampleja3DesktopPrivate *) s->desktop->specific_data;
00408     Sampleja3SessionPrivate *sp = (Sampleja3SessionPrivate *) s->specific_data;
00409     IMText *p;
00410     iml_inst *lp;
00411     int lookup_aux_integers[3];
00412 
00413     iml_session_t *ls = dp->luc_session;
00414 
00415     printf("sampleja3_receive_keyevent keycode=%x keychar=%x modifier=%x\n",
00416           key->keyCode, key->keyChar, key->modifier);
00417 
00418     if (ls) {
00419        sp = (Sampleja3SessionPrivate *) ls->specific_data;
00420        if (key->keyCode == IM_VK_SPACE) {
00421            sp->lookup_current_candidate++;
00422            if (sp->lookup_current_candidate >= NUM_CANDIDATES) {
00423               sp->lookup_current_candidate = 0;
00424            }
00425            p = make_imtext(ls, LUC_CANDIDATES[sp->lookup_current_candidate]);
00426            lp = ls->If->m->iml_make_preedit_draw_inst(ls, p);
00427            ls->If->m->iml_execute(ls, &lp);
00428 
00429            luc_draw(ls, sp->lookup_current_candidate);
00430 
00431            return;
00432        } else if (key->keyCode == IM_VK_UP) {
00433            if (sp->lookup_current_candidate == 0) {
00434               sp->lookup_current_candidate = NUM_CANDIDATES - 1;
00435            } else {
00436               sp->lookup_current_candidate--;
00437            }
00438 
00439            p = make_imtext(ls, LUC_CANDIDATES[sp->lookup_current_candidate]);
00440            lp = ls->If->m->iml_make_preedit_draw_inst(ls, p);
00441            ls->If->m->iml_execute(ls, &lp);
00442 
00443            luc_draw(ls, sp->lookup_current_candidate);
00444            return;
00445        } else if (key->keyCode >= IM_VK_1 && key->keyCode <= IM_VK_9) {
00446            int index = key->keyCode - IM_VK_1;
00447 
00448            sampleja3_commit_string(ls, LUC_CANDIDATES[index]);
00449 
00450            aux_luc_done(ls);
00451 
00452            dp->luc_session = 0;
00453            sp->lookup_current_candidate = 0;
00454            return;
00455        } else if (key->keyCode == IM_VK_ENTER || key->keyCode == IM_VK_DOWN) {
00456 
00457            sampleja3_commit_string(ls, LUC_CANDIDATES[sp->lookup_current_candidate]);
00458 
00459            aux_luc_done(ls);
00460 
00461            dp->luc_session = 0;
00462            sp->lookup_current_candidate = 0;
00463            return;
00464        } else {
00465            sampleja3_commit_string(ls, LUC_CANDIDATES[sp->lookup_current_candidate]);
00466 
00467            aux_luc_done(ls);
00468 
00469            dp->luc_session = 0;
00470            sp->lookup_current_candidate = 0;
00471        }
00472     } else {
00473        if (key->modifier & IM_CTRL_MASK) {
00474            if (key->keyCode == IM_VK_SPACE) {
00475               sampleja3_conversion_off(s);
00476               return;
00477            }
00478        } else {
00479            if (key->keyCode == IM_VK_B) {
00480               p = make_imtext(s, LUC_CANDIDATES[sp->lookup_current_candidate]);
00481               lp = s->If->m->iml_make_preedit_draw_inst(s, p);
00482               s->If->m->iml_execute(s, &lp);
00483               return;
00484 
00485            } else if (key->keyCode == IM_VK_SPACE) {
00486               ls = dp->luc_session = s;
00487               sp->lookup_current_candidate++;
00488 
00489               p = make_imtext(ls, LUC_CANDIDATES[sp->lookup_current_candidate]);
00490               lp = ls->If->m->iml_make_preedit_draw_inst(ls, p);
00491               ls->If->m->iml_execute(ls, &lp);
00492 
00493               luc_draw(ls, sp->lookup_current_candidate);
00494 
00495               return;
00496            }
00497        }
00498     }
00499 
00500     lp = s->If->m->iml_make_keypress_inst(s, (IMKeyEventStruct *) key);
00501     s->If->m->iml_execute(s, &lp);
00502 }
00503 
00504 UTFCHAR title_string[] = {'L', 'O', 'O', 'K', 'U', 'P'};
00505 
00506 luc_draw(iml_session_t * s, int index)
00507 {
00508     int i;
00509     int j = 0;
00510     int k = 0;
00511     iml_inst *lp;
00512     int max_len = 0;
00513     IMText *current_text;
00514     int len;
00515     int luc_top = 0;
00516     UTFCHAR buf[BUFSIZE];
00517 
00518     Sampleja3SessionPrivate *sp = (Sampleja3SessionPrivate *) s->specific_data;
00519     Sampleja3DesktopPrivate *dp = (Sampleja3DesktopPrivate *) s->desktop->specific_data;
00520 
00521     IMText **candidates;
00522     IMText **labels;
00523     IMLookupDrawCallbackStruct *draw;
00524     IMLookupStartCallbackStruct *start;
00525 
00526     candidates = (IMText **) s->If->m->iml_new(s, NUM_CANDIDATES * sizeof(IMText *));
00527     memset(candidates, 0, NUM_CANDIDATES * sizeof(IMText *));
00528 
00529     for (i = 0; i < NUM_CANDIDATES; i++) {
00530        candidates[i] = (IMText *) s->If->m->iml_new(s, sizeof(IMText));
00531        memset(candidates[i], 0, sizeof(IMText));
00532        candidates[i]->encoding = UTF16_CODESET;
00533        candidates[i]->count_annotations = 0;
00534        candidates[i]->annotations = NULL;
00535        candidates[i]->char_length = UTFCHARLen(LUC_CANDIDATES[i]);
00536        candidates[i]->text.utf_chars = (UTFCHAR *) s->If->m->iml_new(s, sizeof(UTFCHAR) * candidates[i]->char_length);
00537        memcpy(candidates[i]->text.utf_chars, LUC_CANDIDATES[i], sizeof(UTFCHAR) * candidates[i]->char_length);
00538        candidates[i]->feedback = create_feedback(s, candidates[i]->char_length);
00539     }
00540 
00541     labels = (IMText **) s->If->m->iml_new(s, NUM_CANDIDATES * sizeof(IMText *));
00542     memset(labels, 0, NUM_CANDIDATES * sizeof(IMText *));
00543     for (i = '1'; i <= '9'; i++, j++) {
00544        labels[j] = (IMText *) s->If->m->iml_new(s, sizeof(IMText));
00545        labels[j]->encoding = UTF16_CODESET;
00546        labels[j]->count_annotations = 0;
00547        labels[j]->annotations = NULL;
00548        labels[j]->char_length = 1;
00549        labels[j]->text.utf_chars = (UTFCHAR *) s->If->m->iml_new(s, sizeof(UTFCHAR));
00550        labels[j]->text.utf_chars[0] = (UTFCHAR) i;
00551        labels[j]->feedback = create_feedback(s, labels[j]->char_length);
00552     }
00553 
00554     start = (IMLookupStartCallbackStruct *) s->If->m->iml_new(s, sizeof(IMLookupStartCallbackStruct));
00555     start->whoIsMaster = IMIsMaster;
00556     start->IMPreference = (LayoutInfo *) s->If->m->iml_new(s, sizeof(LayoutInfo));
00557     start->IMPreference->choice_per_window = NUM_CANDIDATES;
00558     start->IMPreference->ncolumns = 1;
00559     start->IMPreference->nrows = NUM_CANDIDATES;
00560     start->IMPreference->drawUpDirection = DrawUpHorizontally;
00561     start->IMPreference->whoOwnsLabel = IMOwnsLabel;
00562     start->CBPreference = NULL;
00563 
00564     aux_luc_start(s, start);
00565 
00566     draw = (IMLookupDrawCallbackStruct *) s->If->m->iml_new(s, sizeof(IMLookupDrawCallbackStruct));
00567     draw->index_of_first_candidate = 0;
00568     draw->index_of_last_candidate = NUM_CANDIDATES - 1;
00569     draw->n_choices = draw->index_of_last_candidate - draw->index_of_first_candidate + 1;
00570 
00571     draw->title = (IMText *) s->If->m->iml_new(s, sizeof(IMText));
00572     draw->title->encoding = UTF16_CODESET;
00573     draw->title->count_annotations = 0;
00574     draw->title->annotations = NULL;
00575     draw->title->char_length = 6;
00576     draw->title->text.utf_chars = (UTFCHAR *) s->If->m->iml_new(s, sizeof(UTFCHAR) * draw->title->char_length);
00577     memcpy(draw->title->text.utf_chars, title_string, sizeof(UTFCHAR) * draw->title->char_length);
00578     draw->title->feedback = create_feedback(s, draw->title->char_length);
00579 
00580     draw->choices = (IMChoiceObject *) s->If->m->iml_new(s, draw->n_choices * sizeof(IMChoiceObject));
00581 
00582     for (i = 0; i < draw->n_choices; i++) {
00583        IMText *vt;          /* for value */
00584        IMText *lt;          /* for label */
00585        vt = draw->choices[i].value = candidates[i + luc_top];
00586        lt = draw->choices[i].label = labels[i];
00587 
00588        if (max_len < vt->char_length) {
00589            max_len = vt->char_length;
00590        }
00591     }
00592     draw->max_len = 20;
00593     draw->index_of_current_candidate = index;
00594 
00595     aux_luc_draw(s, draw);
00596 }
00597 
00598 IMText *make_imtext(iml_session_t * s, UTFCHAR * p);
00599 
00600 void
00601 sampleja3_conversion_on(
00602                  iml_session_t * s
00603 )
00604 {
00605     int int_values[1];
00606     UTFCHAR on_status_string[] = {'O', 'N', 0x0};
00607 
00608     /* drawing status string */
00609     iml_inst *lp;
00610     lp = s->If->m->iml_make_preedit_start_inst(s);
00611     s->If->m->iml_execute(s, &lp);
00612     lp = s->If->m->iml_make_status_draw_inst(s, make_imtext(s, on_status_string));
00613     s->If->m->iml_execute(s, &lp);
00614 
00615     int_values[0] = SAMPLEJA3_AUXPALETTE_CONVON;
00616 
00617     /* sending to AUX */
00618     aux_draw(s,
00619                AUX_PALETTE_CLASS_NAME,
00620                1, int_values,
00621                0, 0);
00622 }
00623 
00624 void
00625 sampleja3_conversion_off(
00626                   iml_session_t * s
00627 )
00628 {
00629     int int_values[1];
00630     UTFCHAR off_status_string[] = {'O', 'F', 'F', 0x0};
00631     iml_inst *lp;
00632     lp = s->If->m->iml_make_end_conversion_inst(s);
00633     s->If->m->iml_execute(s, &lp);
00634     lp = s->If->m->iml_make_status_draw_inst(s, make_imtext(s, off_status_string));
00635     s->If->m->iml_execute(s, &lp);
00636 
00637     int_values[0] = SAMPLEJA3_AUXPALETTE_CONVOFF;
00638 
00639     /* sending to AUX */
00640     aux_draw(s,
00641                AUX_PALETTE_CLASS_NAME,
00642                1, int_values,
00643                0, 0);
00644 }
00645 
00646 void
00647 sampleja3_commit_string(
00648                  iml_session_t * s,
00649                  UTFCHAR * string
00650 )
00651 {
00652     iml_inst *lp;
00653     IMText *p;
00654 
00655     /* erase first */
00656     lp = s->If->m->iml_make_preedit_erase_inst(s);
00657     s->If->m->iml_execute(s, &lp);
00658 
00659     /* commit */
00660     p = make_imtext(s, string);
00661     lp = s->If->m->iml_make_commit_inst(s, p);
00662     s->If->m->iml_execute(s, &lp);
00663 }
00664 
00665 void
00666 aux_start(
00667          iml_session_t * s,
00668          char *class_name
00669 )
00670 {
00671     iml_inst *lp;
00672     IMAuxStartCallbackStruct *aux = (IMAuxStartCallbackStruct *) s->If->m->iml_new(s, sizeof(IMAuxStartCallbackStruct));
00673     aux->aux_name = class_name;
00674     lp = s->If->m->iml_make_aux_start_inst(s, aux);
00675 printf("aux_start\n");
00676     s->If->m->iml_execute(s, &lp);
00677 }
00678 
00679 void
00680 aux_done(
00681         iml_session_t * s,
00682         char *class_name
00683 )
00684 {
00685     iml_inst *lp;
00686     IMAuxDoneCallbackStruct *aux = (IMAuxDoneCallbackStruct *) s->If->m->iml_new(s, sizeof(IMAuxDoneCallbackStruct));
00687     aux->aux_name = class_name;
00688     lp = s->If->m->iml_make_aux_done_inst(s, aux);
00689     s->If->m->iml_execute(s, &lp);
00690 }
00691 
00692 void
00693 aux_draw2(
00694          iml_session_t * s,
00695          char *class_name,
00696          int count_integers,
00697          int *integers,
00698          int count_strings,
00699          IMText * texts
00700 )
00701 {
00702     iml_inst *lp;
00703     int i, len, pp;
00704     IMText *lts, *lt, *ltp = texts;
00705     IMAuxDrawCallbackStruct *aux;
00706 
00707     aux = (IMAuxDrawCallbackStruct *) s->If->m->iml_new(s, sizeof(IMAuxDrawCallbackStruct));
00708     memset(aux, 0, sizeof(IMAuxDrawCallbackStruct));
00709     aux->aux_name = class_name;
00710 
00711     aux->count_integer_values = count_integers;
00712     if (aux->count_integer_values) {
00713        aux->integer_values = (int *) s->If->m->iml_new(s, sizeof(int) * aux->count_integer_values);
00714        memset(aux->integer_values, 0, sizeof(int) * aux->count_integer_values);
00715 
00716        for (i = 0; i < aux->count_integer_values; i++) {
00717            aux->integer_values[i] = integers[i];
00718        }
00719     }
00720     aux->count_string_values = count_strings;
00721     if (aux->count_string_values) {
00722        aux->string_values = lts = (IMText *) s->If->m->iml_new(s, sizeof(IMText) * aux->count_string_values);
00723        memset(aux->string_values, 0, sizeof(IMText) * aux->count_string_values);
00724        for (i = 0, lt = lts; i < aux->count_string_values; i++, lt++, ltp++) {
00725            len = ltp->char_length;
00726            lt->text.utf_chars = (UTFCHAR *) s->If->m->iml_new(s, sizeof(UTFCHAR) * len);
00727            lt->char_length = len;
00728            memcpy(lt->text.utf_chars, ltp->text.utf_chars, sizeof(UTFCHAR) * len);
00729        }
00730     }
00731     lp = s->If->m->iml_make_aux_draw_inst(s, aux);
00732     s->If->m->iml_execute(s, &lp);
00733 }
00734 
00735 void
00736 aux_draw(
00737         iml_session_t * s,
00738         char *class_name,
00739         int count_integers,
00740         int *integers,
00741         int count_strings,
00742         UTFCHAR ** strings
00743 )
00744 {
00745     iml_inst *lp;
00746     int i, len;
00747     IMText *lts, *lt;
00748     IMAuxDrawCallbackStruct *aux;
00749 
00750     aux = (IMAuxDrawCallbackStruct *) s->If->m->iml_new(s, sizeof(IMAuxDrawCallbackStruct));
00751     memset(aux, 0, sizeof(IMAuxDrawCallbackStruct));
00752     aux->aux_name = class_name;
00753 
00754     aux->count_integer_values = count_integers;
00755     if (aux->count_integer_values) {
00756        aux->integer_values = (int *) s->If->m->iml_new(s, sizeof(int) * aux->count_integer_values);
00757        memset(aux->integer_values, 0, sizeof(int) * aux->count_integer_values);
00758 
00759        for (i = 0; i < aux->count_integer_values; i++) {
00760            aux->integer_values[i] = integers[i];
00761        }
00762     }
00763     aux->count_string_values = count_strings;
00764     if (aux->count_string_values) {
00765        aux->string_values = lts = (IMText *) s->If->m->iml_new(s, sizeof(IMText) * aux->count_string_values);
00766        memset(aux->string_values, 0, sizeof(IMText) * aux->count_string_values);
00767        for (i = 0, lt = lts; i < aux->count_string_values; i++, lt++) {
00768            len = UTFCHARLen(strings[i]);
00769            lt->text.utf_chars = (UTFCHAR *) s->If->m->iml_new(s, sizeof(UTFCHAR) * len);
00770            lt->char_length = len;
00771            memcpy(lt->text.utf_chars, strings[i], sizeof(UTFCHAR) * len);
00772        }
00773     }
00774     lp = s->If->m->iml_make_aux_draw_inst(s, aux);
00775     s->If->m->iml_execute(s, &lp);
00776 }
00777 
00778 int
00779 UTFCHARLen(
00780           UTFCHAR * p
00781 )
00782 {
00783     int i;
00784     for (i = 0; *p; i++)
00785        p++;
00786     return i;
00787 }
00788 
00789 void
00790 sampleja3_receive_aux(
00791                iml_session_t * s,
00792                IMAuxDrawCallbackStruct * aux
00793 )
00794 {
00795     IMText *lts, *lt;
00796     int i, j;
00797 
00798     printf("Received AUX data\n");
00799 
00800     printf("\taux_name=[%s]\n", aux->aux_name);
00801     printf("\tcount_integer_values=[%d]\n", aux->count_integer_values);
00802     printf("\tcount_string_values=[%d]\n", aux->count_string_values);
00803 
00804     printf("\t** INT[] **\n");
00805     for (i = 0; i < aux->count_integer_values; i++) {
00806        printf("\t%3d:0x%08x\n", i, aux->integer_values[i]);
00807     }
00808 
00809     printf("\t** STR[] **\n");
00810     lts = aux->string_values;
00811     for (i = 0, lt = lts; i < aux->count_string_values; i++, lt++) {
00812        printf("\t%3d:[%d]", i, lt->char_length);
00813        for (j = 0; j < lt->char_length; j++) {
00814            printf("[%x]", lt->text.utf_chars[j]);
00815        }
00816        printf("\n");
00817     }
00818 }
00819 
00820 
00821 IMFeedbackList *
00822 create_feedback(
00823               iml_session_t * s,
00824               int size
00825 )
00826 {
00827     int i;
00828     IMFeedbackList *feedback, *fbl;
00829     IMFeedback *fb;
00830 
00831     if (s) {
00832        feedback = (IMFeedbackList *) s->If->m->iml_new(s, sizeof(IMFeedbackList) * size);
00833     } else {
00834        feedback = (IMFeedbackList *) calloc(1, sizeof(IMFeedbackList) * size);
00835     }
00836     for (i = 0; i < size; i++) {
00837        IMFeedbackList *fbl = &feedback[i];
00838        fbl->count_feedbacks = 1;
00839        if (s) {
00840            fb = fbl->feedbacks = (IMFeedback *) s->If->m->iml_new(s, sizeof(IMFeedback) * 4);
00841        } else {
00842            fb = fbl->feedbacks = (IMFeedback *) calloc(1, sizeof(IMFeedback) * 4);
00843        }
00844        memset(fbl->feedbacks, 0, sizeof(IMFeedback) * 4);
00845     }
00846     return feedback;
00847 }
00848 
00849 void
00850 set_feedback_private(
00851                    IMFeedbackList * fbl,
00852                    int normalfeedback,
00853                    int fg,
00854                    int bg,
00855                    int underline
00856 )
00857 {
00858     int count = 0;
00859     IMFeedback *fb;
00860 
00861     fb = &fbl->feedbacks[count];
00862     IM_FEEDBACK_TYPE(fb) = IM_DECORATION_FEEDBACK;
00863     IM_FEEDBACK_VALUE(fb) = normalfeedback;
00864     count++;
00865 
00866     if (fg != -1) {
00867        fb = &fbl->feedbacks[count];
00868        IM_FEEDBACK_TYPE(fb) = IM_FOREGROUND_RGB_FEEDBACK;
00869        IM_FEEDBACK_VALUE(fb) = fg;
00870        count++;
00871     }
00872     if (bg != -1) {
00873        fb = &fbl->feedbacks[count];
00874        IM_FEEDBACK_TYPE(fb) = IM_BACKGROUND_RGB_FEEDBACK;
00875        IM_FEEDBACK_VALUE(fb) = bg;
00876        count++;
00877     }
00878     if (underline != -1) {
00879        fb = &fbl->feedbacks[count];
00880        IM_FEEDBACK_TYPE(fb) = IM_UNDERLINE_RGB_FEEDBACK;
00881        IM_FEEDBACK_VALUE(fb) = underline;
00882        count++;
00883     }
00884     IM_FEEDBACK_COUNT(fbl) = count;
00885 }
00886 
00887 IMText *
00888 make_imtext(iml_session_t * s, UTFCHAR * p)
00889 {
00890     int len;
00891     int i;
00892     IMText *text = (IMText *) s->If->m->iml_new(s, sizeof(IMText));
00893     memset(text, 0, sizeof(IMText));
00894 
00895     len = UTFCHARLen(p);
00896     text->text.utf_chars = (UTFCHAR *) s->If->m->iml_new(s, sizeof(UTFCHAR) * len);
00897     memcpy(text->text.utf_chars, p, sizeof(UTFCHAR) * len);
00898     text->char_length = len;
00899     text->feedback = create_feedback(s, text->char_length);
00900     for (i = 0; i < text->char_length; i++) {
00901        set_feedback_private(&text->feedback[i], IMReverse, -1, -1, -1);
00902     }
00903     return text;
00904 }
00905 
00906 aux_luc_start(
00907              iml_session_t * s,
00908              IMLookupStartCallbackStruct * start
00909 )
00910 {
00911     if (!getenv("DONOTUSE_AUXLUC")) {
00912        int int_values[6];
00913 
00914        int_values[0] = SAMPLEJA3_AUXLUC_START;
00915        int_values[1] = start->IMPreference->choice_per_window;
00916        int_values[2] = start->IMPreference->ncolumns;
00917        int_values[3] = start->IMPreference->nrows;
00918        int_values[4] = start->IMPreference->drawUpDirection;
00919 
00920        aux_draw(s,
00921                AUX_LUC_CLASS_NAME,
00922                5, int_values,
00923                0, 0);
00924     } else {
00925        iml_inst *lp = s->If->m->iml_make_lookup_start_inst(s, start);
00926        s->If->m->iml_execute(s, &lp);
00927     }
00928 }
00929 
00930 aux_luc_done(
00931             iml_session_t * s
00932 )
00933 {
00934     if (!getenv("DONOTUSE_AUXLUC")) {
00935        int int_values[1];
00936        int_values[0] = SAMPLEJA3_AUXLUC_DONE;
00937        aux_draw(s,
00938                AUX_LUC_CLASS_NAME,
00939                1, int_values,
00940                0, 0);
00941     } else {
00942        iml_inst *lp = s->If->m->iml_make_lookup_done_inst(s);
00943        s->If->m->iml_execute(s, &lp);
00944     }
00945 }
00946 
00947 aux_luc_draw(
00948             iml_session_t * s,
00949             IMLookupDrawCallbackStruct * draw
00950 )
00951 {
00952     if (!getenv("DONOTUSE_AUXLUC")) {
00953        int i, n = 0;
00954 
00955        int int_values[6];
00956        IMText *texts, *lt, *lts;
00957 
00958        int_values[0] = SAMPLEJA3_AUXLUC_DRAW;
00959        int_values[1] = draw->index_of_current_candidate;
00960        int_values[2] = draw->n_choices;
00961        int_values[3] = draw->index_of_first_candidate;
00962        int_values[4] = draw->index_of_last_candidate;
00963 
00964        texts = (IMText *) s->If->m->iml_new(s, draw->n_choices * sizeof(IMText));
00965        memset(texts, 0, draw->n_choices * sizeof(IMText));
00966        for (i = 0, lt = texts; i < draw->n_choices; i++, lt++) {
00967            lts = draw->choices[i].value;
00968            lt->char_length = lts->char_length;
00969            lt->text.utf_chars = (UTFCHAR *) s->If->m->iml_new(s, sizeof(UTFCHAR) * lt->char_length);
00970            memcpy(lt->text.utf_chars, lts->text.utf_chars, sizeof(UTFCHAR) * lt->char_length);
00971        }
00972 
00973        aux_draw2(s,
00974                 AUX_LUC_CLASS_NAME,
00975                 5, int_values,
00976                 draw->n_choices, texts);
00977 
00978     } else {
00979        iml_inst *lp = s->If->m->iml_make_lookup_draw_inst(s, draw);
00980        s->If->m->iml_execute(s, &lp);
00981     }
00982 }
00983 
00984 /* Modify AUX event to KeyEvent */
00985 
00986 IMInputEvent *
00987 modify_event(
00988             iml_session_t * s,
00989             IMInputEvent * ev
00990 )
00991 {
00992     static IMKeyEventStruct akey;
00993     static IMKeyListEvent keyev;
00994 
00995     if (ev->type == IM_EventAux) {
00996        IMAuxDrawCallbackStruct *aux_data = ((IMAuxEvent *) ev)->aux;
00997        if (aux_data->count_integer_values == 4 &&
00998            aux_data->integer_values[0] == SAMPLEJA3_AUXSETVAL_KEYPRESS) {
00999            akey.keyCode = aux_data->integer_values[1];
01000            akey.keyChar = aux_data->integer_values[2];
01001            akey.modifier = aux_data->integer_values[3];
01002            keyev.type = IM_EventKeyList;
01003            keyev.keylist = (IMKeyList) & akey;
01004            return (IMInputEvent *) & keyev;
01005        }
01006     }
01007     return ev;
01008 }