Back to index

im-sdk  12.3.91
le_auxevent.c
Go to the documentation of this file.
00001 #include <stdio.h>
00002 
00003 #include "le_info.h"
00004 #include "le_session.h"
00005 #include "le_aux_protocol.h"
00006 
00007 #include "ime.h"
00008 
00009 void le_show_selectaux_notify(iml_session_t * s);
00010 void le_update_aux_imeinfo_notify(iml_session_t * s, char *classname);
00011 void le_show_propertiesaux_notify(iml_session_t * s);
00012 
00013 LeResult le_proc_paletteaux_update_property_event(iml_session_t * s,
00014                                                   IMAuxDrawCallbackStruct * aux_data);
00015 
00016 LeResult le_proc_paletteaux_connect_event(iml_session_t * s,
00017                                           IMAuxDrawCallbackStruct *
00018                                           aux_data);
00019 LeResult le_proc_paletteaux_switch_engine_event(iml_session_t * s,
00020                                                 IMAuxDrawCallbackStruct *
00021                                                 aux_data);
00022 LeResult le_proc_paletteaux_switch_qjbj_event(iml_session_t * s,
00023                                               IMAuxDrawCallbackStruct *
00024                                               aux_data);
00025 LeResult le_proc_paletteaux_switch_punct_event(iml_session_t * s,
00026                                                IMAuxDrawCallbackStruct *
00027                                                aux_data);
00028 LeResult le_proc_commonaux_commit_string_event(iml_session_t * s,
00029                                                IMAuxDrawCallbackStruct *
00030                                                aux_data);
00031 LeResult le_proc_commonaux_commit_key_event(iml_session_t * s,
00032                                             IMAuxDrawCallbackStruct *
00033                                             aux_data);
00034 
00035 LeResult le_proc_pc_style_change                   (iml_session_t            *s,
00036                                                     IMAuxDrawCallbackStruct  *aux_data);
00037 
00038 LeResult le_proc_pc_candidate_selection            (iml_session_t            *s,
00039                                                     IMAuxDrawCallbackStruct  *aux_data);
00040 
00041 LeResult le_proc_pc_candidate_page                 (iml_session_t            *s,
00042                                                     IMAuxDrawCallbackStruct  *aux_data);
00043 
00044 LeResult le_proc_pc_move                           (iml_session_t            *s,
00045                                                     IMAuxDrawCallbackStruct  *aux_data);
00046 
00047 
00048 LeResult le_update_pc_position                     (iml_session_t *s,
00049                                                     char          *classname,
00050                                                     int            cursor_x,
00051                                                     int            cursor_y,
00052                                                     int            cursor_w,
00053                                                     int            cursor_h);
00054 
00055 //UTF-16 -->encodingid
00056 static IMAuxDrawCallbackStruct* convertAuxEventEncoding(IMAuxDrawCallbackStruct * auxdata, int encoding_id)
00057 {
00058     int i, sz, srclen, dstlen;
00059     char * dstbuf;
00060     IMAuxDrawCallbackStruct *ad = (IMAuxDrawCallbackStruct*)calloc(1, sizeof(IMAuxDrawCallbackStruct));
00061 
00062     *ad = *auxdata;
00063     ad->string_values = NULL;
00064     if (ad->count_string_values) {
00065         ad->string_values = (IMText *)calloc(ad->count_string_values, sizeof(IMText));
00066         memset(ad->string_values, 0, sizeof(IMText)*ad->count_string_values);
00067         for (i=0; i < ad->count_string_values; ++i) {
00068             ad->string_values[i] = auxdata->string_values[i];
00069             ad->string_values[i].encoding = encoding_id;
00070             srclen = sizeof(UTFCHAR)*ad->string_values[i].char_length;
00071             dstlen = sz = ad->string_values[i].char_length*6;
00072             dstbuf = ad->string_values[i].text.native_chars = (char*)calloc(sz, sizeof(char));
00073 
00074             Convert_UTF16_To_Native(encoding_id,
00075                                     auxdata->string_values[i].text.utf_chars, srclen,
00076                                     &dstbuf, &dstlen);
00077         }
00078     }
00079     return ad;
00080 }
00081 
00082 static void freeConvertedEvent(IMAuxDrawCallbackStruct* auxdata)
00083 {
00084     int i;
00085     if (auxdata) {
00086         if (auxdata->string_values) {
00087             for (i=0; i < auxdata->count_string_values; ++i) {
00088                 if (auxdata->string_values[i].text.native_chars)
00089                     free(auxdata->string_values[i].text.native_chars);
00090             }
00091             free(auxdata->string_values);
00092         }
00093         free(auxdata);
00094     }
00095     return;
00096 }
00097 
00098 /* ============================================================== */
00099 /*            Process information from Auxiliary Window           */
00100 /* ============================================================== */
00101 LeResult le_session_proc_aux_event(iml_session_t * s,
00102                                    IMAuxEvent * auxevent)
00103 {
00104 
00105     LeDesktopContextRec *le_desktop_context = NULL;
00106 
00107     IMAuxDrawCallbackStruct *aux_data = auxevent->aux;
00108     int nIntegerCount, *pIntegerList;
00109     int reqType;
00110     int ret = LE_OK;
00111 
00112     le_desktop_context = (LeDesktopContextRec *) le_session_get_desktop_context(s);
00113 #if 0
00114     /* NEED CHECK WHETHER HAVE OTHER PROBLEM */
00115     s = (iml_session_t *) le_desktop_context_get_current_session(le_desktop_context);
00116 
00117     DEBUG_printf("le_session_proc_aux_event: desktop: %p, current_session:%p\n",
00118                   le_desktop_context, s);
00119 
00120     if (s == NULL || aux_data == NULL)
00121         return (LE_FAIL);
00122 #endif
00123 
00124     nIntegerCount = aux_data->count_integer_values;
00125     pIntegerList = aux_data->integer_values;
00126 
00127     if (nIntegerCount <= 0)
00128         return (LE_FAIL);
00129 
00130     reqType = pIntegerList[0];
00131 
00132     DEBUG_printf("reqType: %d\n", reqType);
00133 
00134     aux_data = convertAuxEventEncoding(aux_data, ENCODE_UTF8); //convert string UTF-16 --> UTF-8
00135     switch (reqType) {
00136     case PALETTEAUX_CONNECT:
00137         ret = le_proc_paletteaux_connect_event(s, aux_data);
00138         break;
00139 
00140     case PALETTEAUX_SWITCH_IME:
00141         ret = le_proc_paletteaux_switch_engine_event(s, aux_data);
00142         break;
00143 
00144     case PALETTEAUX_SWITCH_QJBJ:
00145         ret = le_proc_paletteaux_switch_qjbj_event(s, aux_data);
00146         break;
00147 
00148     case PALETTEAUX_SWITCH_PUNCT:
00149         ret = le_proc_paletteaux_switch_punct_event(s, aux_data);
00150         break;
00151 
00152     case COMMONAUX_COMMIT_STRING:
00153         ret = le_proc_commonaux_commit_string_event(s, aux_data);
00154         break;
00155 
00156     case COMMONAUX_COMMIT_KEY:
00157         ret = le_proc_commonaux_commit_key_event(s, aux_data);
00158         break;
00159 
00160     case PALETTEAUX_UPDATE_PROPERTY:
00161         ret = le_proc_paletteaux_update_property_event(s, aux_data);
00162         break;
00163 
00164     case COMPOSITE_PC_OPTION:
00165         ret = le_proc_pc_style_change(s, aux_data);
00166         break;
00167 
00168     case COMPOSITE_PC_CANDIDATE_SELECTION:
00169         ret = le_proc_pc_candidate_selection(s, aux_data);
00170         break;
00171 
00172     case COMPOSITE_PC_CANDIDATE_PAGE:
00173         ret = le_proc_pc_candidate_page(s, aux_data);
00174         break;
00175 
00176     case COMPOSITE_PC_MOVE:
00177         ret = le_proc_pc_move(s, aux_data);
00178         break;
00179     }
00180     freeConvertedEvent(aux_data);
00181 
00182     return (ret);
00183 }
00184 
00185 LeResult le_proc_paletteaux_connect_event(iml_session_t * s,
00186                                           IMAuxDrawCallbackStruct * aux_data)
00187 {
00188     int locale_id;
00189     int ime_info_len;
00190     char *ime_info_str;
00191 
00192     int nIntegerCount, *pIntegerList;
00193     int nStringCount;
00194 
00195     LeDesktopContextRec *le_desktop_context = NULL;
00196 
00197     le_desktop_context =
00198         (LeDesktopContextRec *) le_session_get_desktop_context(s);
00199 
00200     le_desktop_context->palette_aux_started = 1;
00201 
00202     nIntegerCount = aux_data->count_integer_values;
00203     pIntegerList = aux_data->integer_values;
00204     nStringCount = aux_data->count_string_values;
00205 
00206     if (nIntegerCount != 3)
00207         return (LE_FAIL);
00208 
00209     locale_id = pIntegerList[1];
00210     ime_info_len = pIntegerList[2];
00211 
00212     if (ime_info_len > 0 && nStringCount == 1) {
00213         ime_info_str = (char *) aux_data->string_values[0].text.utf_chars;
00214 #if 0
00215         ime_info_str[ime_info_len] = 0;
00216 #endif
00217 
00218 #if DEBUG
00219         printf("ime_info_len: %d\n", ime_info_len);
00220         printf("le_proc_paletteaux_connect_event:  locale_id: %d, ime_info_str:%s\n",
00221                         locale_id, ime_info_str);
00222 #endif
00223 
00224         if (ime_info_str && *ime_info_str) {
00225             LeDesktopContextRec *le_desktop_context;
00226             le_desktop_context =
00227                 (LeDesktopContextRec *) le_session_get_desktop_context(s);
00228             le_desktop_profile_new_from_memory(le_desktop_context, ime_info_str,
00229                                             strlen(ime_info_str));
00230         }
00231     }
00232 
00233     le_update_aux_imeinfo_notify(s, PALETTE_AUX_CLASS_NAME);
00234     return (LE_OK);
00235 }
00236 
00237 LeResult le_proc_paletteaux_update_property_event(iml_session_t * s,
00238                                                   IMAuxDrawCallbackStruct * aux_data)
00239 {
00240     int locale_id;
00241     int ime_info_len;
00242     char *ime_info_str;
00243 
00244     int nIntegerCount, *pIntegerList;
00245     int nStringCount;
00246 
00247     nIntegerCount = aux_data->count_integer_values;
00248     pIntegerList = aux_data->integer_values;
00249     nStringCount = aux_data->count_string_values;
00250 
00251     if (nIntegerCount != 2 || nStringCount != 1)
00252         return (LE_FAIL);
00253 
00254     ime_info_len = pIntegerList[1];
00255     ime_info_str = (char *) aux_data->string_values[0].text.utf_chars;
00256     ime_info_str[ime_info_len-1] = 0;
00257 
00258 #if DEBUG
00259     printf("ime_info_len: %d\n", ime_info_len);
00260     printf("le_proc_paletteaux_update_property_event:  locale_id: %d, ime_info_str:%s\n",
00261                     locale_id, ime_info_str);
00262 #endif
00263 
00264     if (ime_info_str && *ime_info_str) {
00265         LeDesktopContextRec *le_desktop_context;
00266         le_desktop_context =
00267             (LeDesktopContextRec *) le_session_get_desktop_context(s);
00268         le_desktop_profile_new_from_memory(le_desktop_context, ime_info_str,
00269                                         strlen(ime_info_str));
00270     }
00271 
00272     return (LE_OK);
00273 }
00274 
00275 LeResult le_proc_paletteaux_switch_engine_event(iml_session_t * s,
00276                                                 IMAuxDrawCallbackStruct *
00277                                                 aux_data)
00278 {
00279     char *ime_uuid;
00280     ImeModuleRec *ime_module = NULL;
00281 
00282     int nStringCount;
00283 
00284     nStringCount = aux_data->count_string_values;
00285     if (nStringCount != 1) return (LE_FAIL);
00286 
00287     ime_uuid = (char *) aux_data->string_values[0].text.utf_chars;
00288     DEBUG_printf("PALETTEAUX_SWITCH_IME:  uuid:%s\n", ime_uuid);
00289 
00290     if (!ime_uuid || !*ime_uuid) return (LE_FAIL);
00291 
00292     ime_module = (ImeModuleRec *) le_session_get_ime_module_by_uuid(s, ime_uuid);
00293     if (ime_module == NULL) return (LE_FAIL);
00294 
00295     le_session_switch_to_new_ime_module(s, ime_module);
00296     return (LE_OK);
00297 }
00298 
00299 LeResult le_proc_paletteaux_switch_qjbj_event(iml_session_t * s,
00300                                               IMAuxDrawCallbackStruct *
00301                                               aux_data)
00302 {
00303     int qjbj;
00304     int nIntegerCount, *pIntegerList;
00305 
00306     nIntegerCount = aux_data->count_integer_values;
00307     pIntegerList = aux_data->integer_values;
00308 
00309     if (nIntegerCount != 2)
00310         return (LE_FAIL);
00311 
00312     qjbj = pIntegerList[1];
00313     DEBUG_printf("PALETTEAUX_SWITCH_QJBJ:  qjbj:%d\n", qjbj);
00314 
00315     /* FIXME, add functions to process qjbj switching */
00316     le_session_toggle_qjbj_status(s);
00317     return (LE_OK);
00318 }
00319 
00320 LeResult le_proc_paletteaux_switch_punct_event(iml_session_t * s,
00321                                                IMAuxDrawCallbackStruct *
00322                                                aux_data)
00323 {
00324     int punct;
00325     int nIntegerCount, *pIntegerList;
00326 
00327     nIntegerCount = aux_data->count_integer_values;
00328     pIntegerList = aux_data->integer_values;
00329 
00330     if (nIntegerCount != 2)
00331         return (LE_FAIL);
00332 
00333     punct = pIntegerList[1];
00334     DEBUG_printf("PALETTEAUX_SWITCH_PUNCT:  punct: %d\n", punct);
00335 
00336     /* FIXME, add functions to process punct switching */
00337     le_session_toggle_punct_status(s);
00338 
00339     return (LE_OK);
00340 }
00341 
00342 LeResult le_proc_commonaux_commit_string_event(iml_session_t * s,
00343                                                IMAuxDrawCallbackStruct * aux_data)
00344 {
00345     int encoding;
00346     int commit_str_len;
00347     char *commit_str;
00348     UTFCHAR tmp_buf[1024];
00349     UTFCHAR *tmp_ptr = tmp_buf;
00350     int from_len, to_left, ret;
00351 
00352     int nIntegerCount, *pIntegerList;
00353     int nStringCount, nStringLen;
00354 
00355     nIntegerCount = aux_data->count_integer_values;
00356     pIntegerList = aux_data->integer_values;
00357     nStringCount = aux_data->count_string_values;
00358 
00359     if (nIntegerCount != 3 || nStringCount != 1)
00360         return (LE_FAIL);
00361 
00362     encoding = pIntegerList[1];
00363     if (encoding < 0 || encoding > ENCODES_NUM)
00364         return (LE_FAIL);
00365 
00366     commit_str_len = pIntegerList[2];
00367 
00368     commit_str = (char *) aux_data->string_values[0].text.utf_chars;
00369     commit_str[commit_str_len] = 0;
00370 
00371     if (commit_str == NULL)
00372         return (LE_FAIL);
00373 
00374     DEBUG_printf("COMMONAUX_COMMIT_STRING Request Received: \n");
00375     DEBUG_printf("encoding:%d, command_str:%s, len:%d\n",
00376                  encoding, commit_str, strlen(commit_str));
00377 
00378     from_len = strlen(commit_str);
00379     to_left = 1024;
00380     memset(tmp_buf, 0, sizeof(UTFCHAR) * 1024);
00381     ret = Convert_Native_To_UTF16(encoding,
00382                                   commit_str,
00383                                   from_len,
00384                                   (char **) &tmp_ptr,
00385                                   (size_t *) & to_left);
00386     if (ret == -1)
00387         return (LE_FAIL);
00388 
00389     DEBUG_printf("begin do le_iml_commit for session: %p\n", s);
00390     le_iml_commit(s, tmp_buf);
00391 
00392     return (LE_OK);
00393 }
00394 
00395 LeResult le_proc_commonaux_commit_key_event(iml_session_t * s,
00396                                             IMAuxDrawCallbackStruct *
00397                                             aux_data)
00398 {
00399     int keycode, keychar, keystatus;
00400     static IMKeyEventStruct akey;
00401     static IMKeyListEvent keyev;
00402 
00403     int nIntegerCount, *pIntegerList;
00404 
00405     nIntegerCount = aux_data->count_integer_values;
00406     pIntegerList = aux_data->integer_values;
00407 
00408     if (nIntegerCount != 4)
00409         return (LE_FAIL);
00410 
00411     keycode = pIntegerList[1];
00412     keychar = pIntegerList[2];
00413     keystatus = pIntegerList[3];
00414 
00415     DEBUG_printf("COMMONAUX_COMMIT_KEY Request Received: \n");
00416     DEBUG_printf("keycode:0x%x, keychar:0x%x, keystatus:0x%x\n",
00417                  keycode, keychar, keystatus);
00418 
00419     akey.keyCode = keycode;
00420     akey.keyChar = keychar;
00421     akey.modifier = keystatus;
00422     keyev.type = IM_EventKeyList;
00423     keyev.keylist = (IMKeyList) & akey;
00424     le_session_process_key_event(s, (IMKeyListEvent *) & keyev);
00425 
00426     return (LE_OK);
00427 }
00428 
00429 /* ============================================================== */
00430 /*              Send information to Auxiliary Window              */
00431 /* ============================================================== */
00432 void le_update_aux_imeinfo_notify(iml_session_t * s, char *classname)
00433 {
00434     int nIntegerCount, pIntegerList[1];
00435     int nStringsCount, pLenStrings[1];
00436     char *pStrings[1];
00437 
00438     char *ime_info_str;
00439     LeDesktopContextRec *le_desktop_context;
00440 
00441     DEBUG_printf("le_imeinfo_notify: ======\n");
00442 
00443     nIntegerCount = 1;
00444     pIntegerList[0] = COMMONAUX_IME_INFO_NOTIFY;
00445 
00446     le_desktop_context = (LeDesktopContextRec *) le_session_get_desktop_context(s);
00447     ime_info_str = (char *) le_desktop_profile_write_to_memory(le_desktop_context);
00448     if (ime_info_str == NULL)
00449         return;
00450 
00451     nStringsCount = 1;
00452     pLenStrings[0] = strlen(ime_info_str) + 1;
00453     pStrings[0] = (char *) ime_info_str;
00454 
00455 #if DEBUG
00456     printf("ime_info: %s, len: %d\n", ime_info_str, strlen(ime_info_str));
00457 #endif
00458     le_iml_aux_draw_native(s, classname,
00459                            nIntegerCount, pIntegerList,
00460                            ENCODE_UTF8, nStringsCount, pStrings);
00461 
00462     free((char *) ime_info_str);
00463     return;
00464 }
00465 
00466 /**********************************************************/
00467 /*                      Palette Aux                       */
00468 /**********************************************************/
00469 void le_start_aux_objects(iml_session_t * s)
00470 {
00471     LeDesktopContextRec *le_desktop_context = NULL;
00472 
00473     le_desktop_context =
00474         (LeDesktopContextRec *) le_session_get_desktop_context(s);
00475 
00476     if (le_desktop_context->palette_aux_started == 1)
00477         return;
00478 
00479     le_iml_aux_start(s, AUX_OBJECT_CLASS_NAME);
00480     le_iml_aux_start(s, PALETTE_AUX_CLASS_NAME);
00481 }
00482 
00483 void le_change_paletteaux_focus_notify(iml_session_t * s)
00484 {
00485     char *classname = PALETTE_AUX_CLASS_NAME;
00486     int nIntegerCount, pIntegerList[4];
00487     int nStringsCount, pLenStrings[1];
00488     char *pStrings[1];
00489     char *ime_uuid;
00490 
00491     ImeModuleRec *current_ime_module;
00492     int show_status = True;
00493     int qjbj;
00494     int punct;
00495 
00496     current_ime_module =
00497         (ImeModuleRec *) le_session_get_current_ime_module(s);
00498     show_status = le_session_get_conversion_status(s);
00499     qjbj = le_session_get_qjbj_status(s);
00500     punct = le_session_get_punct_status(s);
00501 
00502     if (current_ime_module == NULL)
00503         show_status = False;
00504 
00505     DEBUG_printf("le_change_paletteaux_focus_notify: ======\n");
00506 
00507     nIntegerCount = 4;
00508     pIntegerList[0] = COMMONAUX_CHANGE_FOCUS_NOTIFY;
00509     pIntegerList[1] = show_status;
00510     pIntegerList[2] = qjbj;
00511     pIntegerList[3] = punct;
00512 
00513     ime_uuid = "NoIME";
00514     if (current_ime_module != NULL &&
00515         current_ime_module->info != NULL &&
00516         current_ime_module->info->uuid) {
00517         ime_uuid = (char *) current_ime_module->info->uuid;
00518     }
00519 
00520     DEBUG_printf("ime_uuid: %s\n", ime_uuid);
00521     nStringsCount = 1;
00522     pLenStrings[0] = strlen(ime_uuid) + 1;
00523     pStrings[0] = (char *) ime_uuid;
00524 
00525     le_iml_aux_draw_native(s, classname,
00526                            nIntegerCount, pIntegerList,
00527                            ENCODE_UTF8, nStringsCount, pStrings);
00528 }
00529 
00530 void le_beep_paletteaux_notify(iml_session_t * s, ImeBeepType beep_type)
00531 {
00532     char *classname = PALETTE_AUX_CLASS_NAME;
00533     int nIntegerCount, pIntegerList[2];
00534 
00535     DEBUG_printf("le_beep_paletteaux_notify: ====== beep_type: %d\n", beep_type);
00536 
00537     nIntegerCount = 2;
00538     pIntegerList[0] = PALETTEAUX_BEEP_NOTIFY;
00539     pIntegerList[1] = beep_type;
00540 
00541     le_iml_aux_draw(s, classname, nIntegerCount, pIntegerList, 0, NULL, NULL);
00542 }
00543 
00544 void le_show_paletteaux_notify(iml_session_t * s)
00545 {
00546     char *classname = PALETTE_AUX_CLASS_NAME;
00547     int nIntegerCount, pIntegerList[2];
00548 
00549     DEBUG_printf("le_show_paletteaux_notify: ======\n");
00550 
00551     nIntegerCount = 1;
00552     pIntegerList[0] = COMMONAUX_SHOW_NOTIFY;
00553 
00554     le_iml_aux_draw(s, classname, nIntegerCount, pIntegerList, 0, NULL, NULL);
00555 }
00556 
00557 void le_hide_paletteaux_notify(iml_session_t * s)
00558 {
00559     char *classname = PALETTE_AUX_CLASS_NAME;
00560     int nIntegerCount, pIntegerList[2];
00561 
00562     DEBUG_printf("le_hide_paletteaux_notify: ======\n");
00563 
00564     nIntegerCount = 1;
00565     pIntegerList[0] = COMMONAUX_HIDE_NOTIFY;
00566 
00567     le_iml_aux_draw(s, classname, nIntegerCount, pIntegerList, 0, NULL, NULL);
00568 }
00569 
00570 void le_update_paletteaux_ime_notify(iml_session_t * s)
00571 {
00572     char *classname = PALETTE_AUX_CLASS_NAME;
00573     int nIntegerCount, pIntegerList[2];
00574     int nStringsCount, pLenStrings[1];
00575     char *pStrings[1];
00576     char *ime_uuid;
00577 
00578     int show_status = True;
00579 
00580     ImeModuleRec *current_ime_module;
00581 
00582     current_ime_module =
00583         (ImeModuleRec *) le_session_get_current_ime_module(s);
00584     if (current_ime_module == NULL)
00585         show_status = False;
00586 
00587     DEBUG_printf("le_switch_paletteaux_ime_notify: ======\n");
00588 
00589     nIntegerCount = 2;
00590     pIntegerList[0] = PALETTEAUX_SWITCH_IME_NOTIFY;
00591     pIntegerList[1] = show_status;
00592 
00593     ime_uuid = "NoIME";
00594     if (current_ime_module != NULL &&
00595         current_ime_module->info != NULL &&
00596         current_ime_module->info->uuid) {
00597         ime_uuid = (char *) current_ime_module->info->uuid;
00598     }
00599 
00600     nStringsCount = 1;
00601     pLenStrings[0] = strlen(ime_uuid) + 1;
00602     pStrings[0] = (char *) ime_uuid;
00603 
00604     le_iml_aux_draw_native(s, classname,
00605                            nIntegerCount, pIntegerList,
00606                            ENCODE_UTF8, nStringsCount, pStrings);
00607 }
00608 
00609 void le_update_paletteaux_qjbj_notify(iml_session_t * s)
00610 {
00611     char *classname = PALETTE_AUX_CLASS_NAME;
00612     int nIntegerCount, pIntegerList[2];
00613 
00614     int qjbj = le_session_get_qjbj_status(s);
00615 
00616     DEBUG_printf("le_update_paletteaux_qjbj_notify: ====== qjbj: %d\n",
00617                  qjbj);
00618 
00619     nIntegerCount = 2;
00620     pIntegerList[0] = PALETTEAUX_SWITCH_QJBJ_NOTIFY;
00621     pIntegerList[1] = qjbj;
00622 
00623     le_iml_aux_draw(s, classname, nIntegerCount, pIntegerList, 0, NULL, NULL);
00624 }
00625 
00626 void le_update_paletteaux_punct_notify(iml_session_t * s)
00627 {
00628     char *classname = PALETTE_AUX_CLASS_NAME;
00629     int nIntegerCount, pIntegerList[2];
00630 
00631     int punct = le_session_get_punct_status(s);
00632 
00633     DEBUG_printf("le_update_paletteaux_punct_notify: ======\n");
00634 
00635     nIntegerCount = 2;
00636     pIntegerList[0] = PALETTEAUX_SWITCH_PUNCT_NOTIFY;
00637     pIntegerList[1] = punct;
00638 
00639     le_iml_aux_draw(s, classname, nIntegerCount, pIntegerList, 0, NULL, NULL);
00640 }
00641 
00642 /**********************************************************/
00643 /*                      Select Aux                        */
00644 /**********************************************************/
00645 void le_show_selectaux_notify(iml_session_t * s)
00646 {
00647     char *classname = SELECT_AUX_CLASS_NAME;
00648     int nIntegerCount, pIntegerList[2];
00649 
00650     DEBUG_printf("le_show_selectaux_notify: ======\n");
00651 
00652     nIntegerCount = 1;
00653     pIntegerList[0] = COMMONAUX_SHOW_NOTIFY;
00654 
00655     le_iml_aux_draw(s, classname, nIntegerCount, pIntegerList, 0, NULL, NULL);
00656 }
00657 
00658 void le_show_propertiesaux_notify(iml_session_t * s)
00659 {
00660     char *classname = PROPERTIES_AUX_CLASS_NAME;
00661     int nIntegerCount, pIntegerList[2];
00662 
00663     DEBUG_printf("le_show_propertyaux_notify: ======\n");
00664 
00665     nIntegerCount = 1;
00666     pIntegerList[0] = COMMONAUX_SHOW_NOTIFY;
00667 
00668     le_iml_aux_draw(s, classname, nIntegerCount, pIntegerList, 0, NULL, NULL);
00669 
00670 }
00671 
00672 /**********************************************************/
00673 /*                      CompositeAux                      */
00674 /**********************************************************/
00675 void le_change_compositeaux_option_notify(LeSessionContextRec* le_session_context)
00676 {
00677     int  pIntList[1+sizeof(TImePCAuxOption)/sizeof(int) + 4];
00678 
00679     pIntList[0] = COMPOSITE_PC_OPTION;
00680     *(TImePCAuxOption*)(pIntList+1) = *(TImePCAuxOption*)session_get_pc_style(le_session_context);
00681 
00682     session_get_pc_position(le_session_context,
00683                             pIntList+sizeof(TImePCAuxOption)/sizeof(int)+1,
00684                             pIntList+sizeof(TImePCAuxOption)/sizeof(int)+2,
00685                             pIntList+sizeof(TImePCAuxOption)/sizeof(int)+3,
00686                             pIntList+sizeof(TImePCAuxOption)/sizeof(int)+4);
00687 
00688     le_iml_aux_draw(le_session_context->s,
00689                     session_get_pc_aux_name(le_session_context),
00690                     sizeof(pIntList)/sizeof(int), pIntList,
00691                     0, NULL, NULL);
00692 
00693 }
00694 
00695 void le_show_compositeaux_preedit_notify(iml_session_t * s, char* classname)
00696 {
00697     int nIntegerCount, pIntegerList[2];
00698 
00699     DEBUG_printf("le_show_compositeaux_preedit_notify: ======\n");
00700 
00701     nIntegerCount = 1;
00702     pIntegerList[0] = COMMONAUX_SHOW_PREEDIT_NOTIFY;
00703 
00704     le_iml_aux_draw(s, classname, nIntegerCount, pIntegerList, 0, NULL, NULL);
00705 }
00706 
00707 void le_hide_compositeaux_preedit_notify(iml_session_t * s, char* classname)
00708 {
00709     int nIntegerCount, pIntegerList[2];
00710 
00711     DEBUG_printf("le_hide_compositeaux_preedit_notify: ======\n");
00712 
00713     nIntegerCount = 1;
00714     pIntegerList[0] = COMMONAUX_HIDE_PREEDIT_NOTIFY;
00715 
00716     le_iml_aux_draw(s, classname, nIntegerCount, pIntegerList, 0, NULL, NULL);
00717 }
00718 
00719 LeResult le_update_pc_position                     (iml_session_t *s,
00720                                                     char          *classname,
00721                                                     int            cursor_x,
00722                                                     int            cursor_y,
00723                                                     int            cursor_w,
00724                                                     int            cursor_h)
00725 {
00726     int nIntegerCount, pIntegerList[5];
00727 
00728     nIntegerCount = 5;
00729     pIntegerList[0] = COMPOSITE_PC_MOVE;
00730     pIntegerList[1] = cursor_x;
00731     pIntegerList[2] = cursor_y;
00732     pIntegerList[3] = cursor_w;
00733     pIntegerList[4] = cursor_h;
00734 
00735     le_iml_aux_draw(s, classname, nIntegerCount, pIntegerList, 0, NULL, NULL);
00736 }
00737 
00738 int  le_update_compositeaux_preedit_notify(LeSessionContextRec  *le_session_context,
00739                                            char                 *classname,
00740                                            ImePreeditRec        *ime_preedit)
00741 {
00742     ImeEncoding encoding;
00743     int i, from_len, to_left, ret;
00744     char tmp_buf[1024];
00745     char *tmp_ptr = tmp_buf;
00746 
00747     memset(tmp_buf, 0, sizeof(tmp_buf));
00748     if (ime_preedit && ime_preedit->preedit.text) {
00749         //FIX ME, assume only multibyte string encoding used, including UTF-8
00750         ImeEncoding encoding = le_session_get_current_ime_encoding(le_session_context->s);
00751         from_len = strlen(ime_preedit->preedit.text);
00752         to_left = 1024;
00753         ret = Convert_Native_To_UTF8(encoding,
00754                                  ime_preedit->preedit.text,
00755                                  from_len,
00756                                  (char **) &tmp_ptr,
00757                                  (size_t *) & to_left);
00758         if (ret == -1)
00759             tmp_buf[0] = 0;
00760     }
00761 
00762     DEBUG_printf("le_update_compositeaux_preedit_notify: ====== [%s]\n", tmp_buf);
00763 
00764     int nIntegerCount = 3 + ime_preedit->preedit.count_feedbacks * 4;
00765     int *pIntegerList = (int *)calloc(nIntegerCount, sizeof(int));
00766     if (pIntegerList == NULL)
00767         return IME_FAIL;
00768 
00769     pIntegerList[0] = COMMONAUX_UPDATE_PREEDIT_NOTIFY;
00770     pIntegerList[1] = ime_preedit->caret;
00771     pIntegerList[2] = ime_preedit->cl_start;
00772 
00773     for (i=0; i < ime_preedit->preedit.count_feedbacks; ++i) {
00774         pIntegerList[i*4+3+0] = ime_preedit->preedit.feedbacks[i].type;
00775         pIntegerList[i*4+3+1] = ime_preedit->preedit.feedbacks[i].value;
00776         pIntegerList[i*4+3+2] = ime_preedit->preedit.feedbacks[i].start;
00777         pIntegerList[i*4+3+3] = ime_preedit->preedit.feedbacks[i].length;
00778     }
00779 
00780     tmp_ptr = tmp_buf;
00781     le_iml_aux_draw_native(le_session_context->s, classname,
00782                            nIntegerCount, pIntegerList,
00783                            ENCODE_UTF8, 1, &tmp_ptr);
00784     free(pIntegerList);
00785     return IME_OK;
00786 }
00787 
00788 void le_show_compositeaux_candidates_notify(iml_session_t * s, char* classname)
00789 {
00790     int nIntegerCount, pIntegerList[2];
00791 
00792 
00793     nIntegerCount = 1;
00794     pIntegerList[0] = COMMONAUX_SHOW_CANDIDATES_NOTIFY;
00795 
00796     le_iml_aux_draw(s, classname, nIntegerCount, pIntegerList, 0, NULL, NULL);
00797 }
00798 
00799 void le_hide_compositeaux_candidates_notify(iml_session_t * s, char* classname)
00800 {
00801     int nIntegerCount, pIntegerList[2];
00802 
00803     DEBUG_printf("le_show_compositeaux_candidates_notify: ======\n");
00804 
00805     nIntegerCount = 1;
00806     pIntegerList[0] = COMMONAUX_HIDE_CANDIDATES_NOTIFY;
00807 
00808     le_iml_aux_draw(s, classname, nIntegerCount, pIntegerList, 0, NULL,  NULL);
00809 }
00810 
00811 int le_update_compositeaux_candidates_notify(LeSessionContextRec  *le_session_context,
00812                                               char                 *classname,
00813                                               ImeCandidatesRec     *ime_candidates)
00814 {
00815     char **candidates = NULL;
00816     char tmp_buf[1024];
00817     char *tmp_cand_ptr;
00818 
00819     if (le_session_context == NULL || le_session_context->s == NULL || ime_candidates == NULL)
00820         return IMM_FAIL;
00821 
00822     ImeEncoding encoding = le_session_get_current_ime_encoding(le_session_context->s);
00823     int from_len, to_left, ret, i, j, num_candidates = ime_candidates->count;
00824 
00825     candidates = (char **) calloc(num_candidates+1, sizeof(char *)); //one for title
00826     if (candidates == NULL)  return (IMM_FAIL);
00827 
00828     int nIntegerCount = num_candidates + 4; // + 4*sum(fb_count)
00829     for (i = 0; i <num_candidates; i++) {
00830         ret = -1;
00831         if (ime_candidates != NULL && ime_candidates->candidates[i].text != NULL) {
00832             from_len = strlen(ime_candidates->candidates[i].text);
00833             to_left = 1024;
00834             memset(tmp_buf, 0, sizeof(tmp_buf));
00835             tmp_cand_ptr = tmp_buf;
00836             ret = Convert_Native_To_UTF8(encoding,
00837                                      ime_candidates->candidates[i].text,
00838                                      from_len,
00839                                      (char **) &tmp_cand_ptr,
00840                                      (size_t *) & to_left);
00841         }
00842         if (ret == -1) {
00843              ((char*)tmp_buf)[0] = 0x0;
00844              to_left = 1024;
00845         }
00846 
00847         candidates[i] = (char *)calloc(1024 - to_left + 4, sizeof(char));
00848 
00849         if (candidates[i] != NULL) {
00850             candidates[i][0] = (ime_candidates->numbers)?(ime_candidates->numbers[i]) : ('1' + i);
00851             candidates[i][1] = '.';
00852             candidates[i][2] = ' ';
00853             candidates[i][3] = 0;
00854 
00855             strcat(candidates[i], tmp_buf);
00856         }
00857         nIntegerCount += 4 * ime_candidates->candidates[i].count_feedbacks;
00858     }
00859 
00860     //last one for title
00861     ret = -1;
00862     if (ime_candidates->title) {
00863         from_len = strlen(ime_candidates->title);
00864         to_left = 1024;
00865         memset(tmp_buf, 0, sizeof(tmp_buf));
00866         tmp_cand_ptr = tmp_buf;
00867         ret = Convert_Native_To_UTF8(encoding,
00868                                      ime_candidates->title,
00869                                      from_len,
00870                                      (char **) &tmp_cand_ptr,
00871                                      (size_t *) & to_left);
00872     }
00873     if (ret == -1) {
00874          ((char*)tmp_buf)[0] = 0x0;
00875          to_left = 1024;
00876     }
00877     candidates[i] = (char *)calloc(1024 - to_left + 1, sizeof(char));
00878     if (candidates[i] != NULL) {
00879         strcpy(candidates[i], tmp_buf);
00880     }
00881 
00882     int *pIntegerList = (int*)calloc(nIntegerCount, sizeof(int));
00883 
00884     DEBUG_printf("le_update_compositeaux_candidates_notify: ======\n");
00885 
00886     pIntegerList[0] = COMMONAUX_UPDATE_CANDIDATES_NOTIFY;
00887     pIntegerList[1] = num_candidates;
00888     pIntegerList[2] = ime_candidates->page_state;
00889     pIntegerList[3] = ime_candidates->focus;
00890 
00891     int * p_fb_counts = pIntegerList + 4;
00892     ImeFeedbackRec* pfbs = (ImeFeedbackRec*)(p_fb_counts + num_candidates);
00893     for (i=0; i < num_candidates; ++i) {
00894         p_fb_counts[i] = ime_candidates->candidates[i].count_feedbacks;
00895         memcpy(pfbs, ime_candidates->candidates[i].feedbacks, p_fb_counts[i]*sizeof(ImeFeedbackRec));
00896         for (j=0; j < p_fb_counts[i]; ++j) {
00897             pfbs[j].start += 3; // for number string
00898         }
00899         pfbs += p_fb_counts[i];
00900     }
00901 
00902     le_iml_aux_draw_native(le_session_context->s, classname,
00903                            nIntegerCount, pIntegerList,
00904                            ENCODE_UTF8, num_candidates + 1, candidates);
00905 
00906     free(pIntegerList);
00907     for (i = 0; i < num_candidates+1; i++) {
00908         if (candidates[i]) free(candidates[i]);
00909     }
00910     if (candidates) free(candidates);
00911 }
00912 
00913 LeResult le_proc_pc_style_change                   (iml_session_t            *s,
00914                                                     IMAuxDrawCallbackStruct  *aux_data)
00915 {
00916     int  nIntegerCount = aux_data->count_integer_values;
00917     int *pIntegerList = aux_data->integer_values;
00918 
00919     if (nIntegerCount != 1 + sizeof(TImePCAuxOption)/sizeof(int))
00920         return (LE_FAIL);
00921 
00922     DEBUG_printf("Session change PCAux style\n");
00923     return session_proc_style_change(s, pIntegerList+1);
00924 }
00925 
00926 LeResult le_proc_pc_candidate_selection            (iml_session_t            *s,
00927                                                     IMAuxDrawCallbackStruct  *aux_data)
00928 {
00929     int  nIntegerCount = aux_data->count_integer_values;
00930     int *pIntegerList = aux_data->integer_values;
00931 
00932     if (nIntegerCount != 2) return LE_FAIL;
00933 
00934     DEBUG_printf("candidate selection from client\n");
00935     return session_proc_candidate_selection(s, pIntegerList[1]);
00936 }
00937 
00938 LeResult le_proc_pc_candidate_page                 (iml_session_t            *s,
00939                                                     IMAuxDrawCallbackStruct  *aux_data)
00940 {
00941     int  nIntegerCount = aux_data->count_integer_values;
00942     int *pIntegerList = aux_data->integer_values;
00943 
00944     if (nIntegerCount != 2) return LE_FAIL;
00945 
00946     DEBUG_printf("candidate page request from client\n");
00947     return session_proc_candidate_page(s, pIntegerList[1]);
00948 }
00949 
00950 LeResult le_proc_pc_move                           (iml_session_t            *s,
00951                                                     IMAuxDrawCallbackStruct  *aux_data)
00952 {
00953     int  nIntegerCount = aux_data->count_integer_values;
00954     int *pIntegerList = aux_data->integer_values;
00955 
00956     if (nIntegerCount != 5) return LE_FAIL;
00957 
00958     DEBUG_printf("PC Aux move position\n");
00959     return session_proc_pc_move(s, pIntegerList[1], pIntegerList[2], pIntegerList[3], pIntegerList[4]);
00960 }
00961 
00962