Back to index

im-sdk  12.3.91
le_session.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 LeDesktopContextRec *le_session_get_desktop_context(iml_session_t * s);
00008 LeSessionContextRec *le_session_get_session_context(iml_session_t * s);
00009 ImeModuleRec *le_session_get_current_ime_module(iml_session_t * s);
00010 LeResult le_session_update_status_string(iml_session_t * s,
00011                                          ConversionStatus
00012                                          conversion_status);
00013 
00014 
00015 static LeResult le_session_focus_out(iml_session_t * s);
00016 static LeResult le_session_focus_in(iml_session_t * s);
00017 
00018 /* UTF-8 string of [ Ӣ�� ] */
00019 unsigned char English_Status_UTF[] = {
00020     0xe8, 0x8b, 0xb1, 0x0
00021 };
00022 
00023 unsigned char Chinese_Status_UTF[] = {
00024     0xe4, 0xb8, 0xad, 0x0
00025 };
00026 
00027 /*****************************************
00028       LeSessionContextRec
00029 *****************************************/
00030 LeSessionContextRec *le_session_context_new()
00031 {
00032     LeSessionContextRec *le_session_context = NULL;
00033 
00034     le_session_context = (LeSessionContextRec *) calloc(1, sizeof(LeSessionContextRec));
00035     if (le_session_context == NULL) return (NULL);
00036 
00037     le_session_context->client_encoding = ENCODE_UTF8;
00038     le_session_context->current_ime_module = NULL;
00039     le_session_context->current_qjbj_status = QJBJ_HALFWIDTH;
00040     le_session_context->current_punct_status = PUNCT_ENGLISH;
00041     le_session_context->current_conversion_status = CONVERSION_OFF;
00042 
00043     return (le_session_context);
00044 }
00045 
00046 LeResult le_session_context_destroy(LeSessionContextRec * le_session_context)
00047 {
00048     if (le_session_context == NULL)
00049         return (LE_FAIL);
00050 
00051     free((char *)le_session_context);
00052 
00053     return (LE_OK);
00054 }
00055 
00056 LeResult le_session_context_print(LeSessionContextRec * le_session_context)
00057 {
00058     if (le_session_context == NULL)
00059         return (LE_FAIL);
00060 
00061     return (LE_OK);
00062 }
00063 
00064 
00065 //FIXME, this should be put into server configuration files
00066 static TImePCAuxOption dummyPCOpt[] = {
00067 {
00068     0,    //type, custom;
00069     1,    //showSystemBar;
00070     1,    //followCursor;
00071     1,    //composite;
00072     1,    //showPageControl;
00073     1,    //ignorCandidateTitle;
00074     0,    //candidateVertical;
00075     2,    //candidatePosition -- stick right
00076     0     //candidateTitlePosition -- Left or Above
00077 },
00078 
00079 { //for sunpinyin
00080     0,    //type, custom;
00081     1,    //showSystemBar;
00082     1,    //followCursor;
00083     1,    //composite;
00084     1,    //showPageControl;
00085     1,    //ignorCandidateTitle;
00086     0,    //candidateVertical;
00087     1,    //candidatePosition -- ime specify
00088     1     //candidateTitlePosition -- Left or Above
00089 },
00090 
00091 {
00092     0,    //type, custom;
00093     1,    //showSystemBar;
00094     1,    //followCursor;
00095     0,    //composite;
00096     1,    //showPageControl;
00097     1,    //ignorCandidateTitle;
00098     1,    //candidateVertical;
00099     2,    //candidatePosition -- stick right;
00100     0     //candidateTitlePosition -- Left or Above
00101 }
00102 
00103 };
00104 
00105 void
00106 session_set_pc_position(LeSessionContextRec* le_session_context, 
00107                         int cursor_x, int cursor_y, int cursor_w, int cursor_h)
00108 {
00109     ImeModuleRec *current_ime_module = le_session_context->current_ime_module;
00110     if (current_ime_module != NULL && current_ime_module->info != NULL && current_ime_module->info->uuid != NULL) {
00111         current_ime_module->pc_cursor_x = cursor_x;
00112         current_ime_module->pc_cursor_y = cursor_y;
00113         current_ime_module->pc_cursor_w = cursor_w;
00114         current_ime_module->pc_cursor_h = cursor_h;
00115     }
00116 }
00117 
00118 void
00119 session_get_pc_position(LeSessionContextRec* le_session_context, 
00120                         int *cursor_x, int *cursor_y, int *cursor_w, int *cursor_h)
00121 {
00122     ImeModuleRec *current_ime_module = le_session_context->current_ime_module;
00123     if (current_ime_module != NULL && current_ime_module->info != NULL && current_ime_module->info->uuid != NULL) {
00124         *cursor_x = current_ime_module->pc_cursor_x;
00125         *cursor_y = current_ime_module->pc_cursor_y;
00126         *cursor_w = current_ime_module->pc_cursor_w;
00127         *cursor_h = current_ime_module->pc_cursor_h;
00128     } else {
00129         *cursor_x = 300;
00130         *cursor_y = 500;
00131         *cursor_w = 1;
00132         *cursor_h = 2;
00133     }
00134 }
00135 
00136 char*
00137 session_get_pc_aux_name(LeSessionContextRec* le_session_context)
00138 {
00139     ImeModuleRec *current_ime_module = le_session_context->current_ime_module;
00140     if (current_ime_module != NULL && current_ime_module->info != NULL && current_ime_module->info->uuid != NULL) {
00141         if (current_ime_module->pc_aux_name[0])
00142             return current_ime_module->pc_aux_name;
00143     }
00144     return NULL;
00145 }
00146 
00147 void
00148 session_set_pc_aux_name(LeSessionContextRec* le_session_context, const char* aux_name)
00149 {
00150     ImeModuleRec *current_ime_module = le_session_context->current_ime_module;
00151     if (current_ime_module != NULL && current_ime_module->info != NULL && current_ime_module->info->uuid != NULL) {
00152         strncpy(current_ime_module->pc_aux_name, aux_name, sizeof(current_ime_module->pc_aux_name));
00153     }
00154 }
00155 
00156 TImePCAuxOption*
00157 session_get_pc_style(LeSessionContextRec* le_session_context)
00158 {
00159     ImeModuleRec *current_ime_module = le_session_context->current_ime_module;
00160     if (current_ime_module != NULL && current_ime_module->info != NULL && current_ime_module->info->uuid != NULL) {
00161         return &current_ime_module->pc_aux_options;
00162     }
00163     return NULL;
00164 }
00165 
00166 static void 
00167 session_init_ime_pc_aux_options(LeSessionContextRec   *le_session_context)
00168 {
00169     ImeModuleRec *current_ime_module = le_session_context->current_ime_module;
00170     
00171     if (current_ime_module != NULL && current_ime_module->info != NULL && current_ime_module->info->uuid != NULL) {
00172         if (session_get_pc_aux_name(le_session_context) == NULL) {
00173             session_set_pc_aux_name(le_session_context, COMPOSITE_AUX_CLASS_NAME);
00174             TImePCAuxOption* p_pc_style = session_get_pc_style(le_session_context);
00175             if (strcmp(current_ime_module->info->uuid, "SunPinyin-ef1a0a92-9f0e-410b-b8a8-e6f296c1801c") == 0) {
00176                 *p_pc_style = dummyPCOpt[1];
00177             } else {
00178                 *p_pc_style = dummyPCOpt[2];
00179             }
00180         }
00181     }
00182 }
00183 
00184 static LeResult
00185 session_detach_ime(LeSessionContextRec * le_session_context)
00186 {
00187     ImeModuleRec* current_ime_module = le_session_context->current_ime_module;
00188     if (current_ime_module != NULL) {
00189         if (current_ime_module->methods->ImeDestroySession != NULL) {
00190             current_ime_module->methods->ImeDestroySession((ImeInputContext) le_session_context);
00191             le_session_context->ime_session_data = NULL;
00192         }
00193         le_session_context->preedit_show = 0;
00194         le_session_context->candidates_show = 0;
00195         freeImPreeditInternal(&le_session_context->preedit_backup);
00196         freeImCandidatesInternal(&le_session_context->candidates_backup);
00197 /*
00198         le_session_context->current_ime_module = NULL;
00199 */
00200     }
00201 
00202     /*
00203     if (le_session_context->pc_aux_name) free(le_session_context->pc_aux_name);
00204     if (le_session_context->pc_aux_options) free(le_session_context->pc_aux_options);
00205     le_session_context->pc_aux_name = NULL;
00206     le_session_context->pc_aux_options = NULL;
00207     */
00208 
00209     le_session_context->current_conversion_status = CONVERSION_OFF;
00210 }
00211 
00212 static LeResult
00213 session_attach_ime(LeSessionContextRec * le_session_context, ImeModuleRec* new_ime_module)
00214 {
00215     le_session_context->current_ime_module = new_ime_module;
00216     if (new_ime_module != NULL) {
00217         session_init_ime_pc_aux_options(le_session_context);
00218     
00219         if (new_ime_module->methods->ImeCreateSession != NULL)
00220             new_ime_module->methods->ImeCreateSession((ImeInputContext) le_session_context);
00221 
00222         if (new_ime_module->methods->ImeProcessUIEvent != NULL) {
00223             ImeEventRec trigger;
00224 
00225             trigger.notify_event.type = IME_EVENT_IMM_NOTIFY;
00226             trigger.notify_event.peer = 0;      // should not be used, it is from IMM
00227             trigger.notify_event.ic = (ImeInputContext) le_session_context;
00228             trigger.notify_event.trigger = IMM_TRIGGER_FULL_HALF_SIMBOL;
00229             trigger.notify_event.value = (le_session_context->current_qjbj_status == QJBJ_FULLWIDTH) ? 1 : 0;
00230             new_ime_module->methods-> ImeProcessUIEvent((ImeInputContext) le_session_context, &trigger);
00231 
00232             trigger.notify_event.type = IME_EVENT_IMM_NOTIFY;
00233             trigger.notify_event.peer = 0;      // should not be used, it is from IMM
00234             trigger.notify_event.ic = (ImeInputContext) le_session_context;
00235             trigger.notify_event.trigger = IMM_TRIGGER_FULL_HALF_PUNC;
00236             trigger.notify_event.value = (le_session_context->current_punct_status == PUNCT_CHINESE) ? 1 : 0;
00237             new_ime_module->methods-> ImeProcessUIEvent((ImeInputContext) le_session_context, &trigger);
00238         }
00239         le_session_context->current_conversion_status = CONVERSION_ON;
00240     }
00241     //focus_in should be called later
00242 }
00243 
00244 /*****************************************
00245       LE Session for iml_session_t
00246 *****************************************/
00247 LeSessionContextRec *le_session_create(iml_session_t * s)
00248 {
00249     LeDesktopContextRec *le_desktop_context = NULL;
00250     LeSessionContextRec *le_session_context = NULL;
00251     int default_qjbj_status;
00252     int default_punct_status;
00253     int default_conversion_status;
00254 
00255     le_session_context = (LeSessionContextRec *) s->specific_data;
00256     if (le_session_context != NULL) return (le_session_context);
00257 
00258     le_session_context = (LeSessionContextRec *) le_session_context_new();
00259     if (le_session_context == NULL) return (NULL);
00260 
00261     le_desktop_context = (LeDesktopContextRec *) le_session_get_desktop_context(s);
00262     default_qjbj_status = le_desktop_context_get_default_qjbj_status(le_desktop_context);
00263     default_punct_status = le_desktop_context_get_default_punct_status(le_desktop_context);
00264     default_conversion_status = le_desktop_context_get_default_conversion_status(le_desktop_context);
00265 
00266     le_session_context->current_qjbj_status = default_qjbj_status;
00267     le_session_context->current_punct_status = default_punct_status;
00268     le_session_context->current_conversion_status = default_conversion_status;
00269 
00270     le_session_context->s = s;
00271 
00272     s->specific_data = (void *)le_session_context;
00273 
00274     return (le_session_context);
00275 }
00276 
00277 LeResult le_session_destroy(iml_session_t * s)
00278 {
00279     DEBUG_printf("le_session_destroy: s: 0x%x\n", s);
00280 
00281     LeSessionContextRec* le_session_context = le_session_get_session_context(s);
00282 
00283     if (le_session_context != NULL) {
00284         LeDesktopContextRec* le_desktop_context = (LeDesktopContextRec *)le_session_get_desktop_context(s);
00285         iml_session_t* cfs = (iml_session_t *)le_desktop_context_get_current_session(le_desktop_context); 
00286 
00287         le_session_focus_out(s);
00288         session_detach_ime(le_session_context);
00289         le_session_context_destroy(le_session_context);
00290 
00291         if (cfs == s)
00292             le_desktop_context_set_current_session(le_desktop_context, NULL);
00293     }
00294 
00295     s->specific_data = NULL;
00296 
00297     return (LE_OK);
00298 }
00299 
00300 static
00301 LeResult le_session_focus_out(iml_session_t * s)
00302 {
00303     LeDesktopContextRec* le_desktop_context = (LeDesktopContextRec *)le_session_get_desktop_context(s);
00304     LeSessionContextRec *le_session_context = (LeSessionContextRec *)le_session_get_session_context(s);
00305 
00306     int wrong_seq = 0;
00307     if(le_desktop_context)
00308         wrong_seq = le_desktop_context->focus_seq_wrong;
00309 
00310     if (le_session_context != NULL && !wrong_seq) {
00311             le_session_update_status_string(s, CONVERSION_OFF/*le_session_context->current_conversion_status*/);
00312             le_hide_paletteaux_notify(s);
00313 
00314         ImeModuleRec *current_ime_module = le_session_context->current_ime_module;
00315         if (current_ime_module && current_ime_module->methods && current_ime_module->methods->ImeFocusOut)
00316             current_ime_module->methods->ImeFocusOut((ImeInputContext)le_session_context);
00317 
00318         if (session_get_pc_aux_name(le_session_context)) {
00319             le_hide_candidates_atomic(le_session_context, 0);
00320             le_hide_preedit_atomic(le_session_context, 0);
00321         }
00322     }
00323 
00324     if(le_desktop_context)
00325         le_desktop_context->focus_seq_wrong = 0;
00326 
00327     return (LE_OK);
00328 }
00329 
00330 LeResult le_session_set_focus_out(iml_session_t * s)
00331 {
00332     LeDesktopContextRec* le_desktop_context = (LeDesktopContextRec *)le_session_get_desktop_context(s);
00333     iml_session_t* cfs = (iml_session_t *)le_desktop_context_get_current_session(le_desktop_context); 
00334 
00335     DEBUG_printf("le_session_focus_out: 0x%x, and current focus 0x%x\n", s, cfs);
00336 
00337     le_session_focus_out(s);
00338 
00339     if (cfs == s)
00340         le_desktop_context_set_current_session(le_desktop_context, NULL);
00341 }
00342 
00343 static
00344 LeResult le_session_focus_in(iml_session_t * s)
00345 {
00346     LeSessionContextRec* le_session_context = le_session_get_session_context(s);
00347     if (le_session_context != NULL) {
00348         le_change_paletteaux_focus_notify(s);
00349 
00350         le_update_paletteaux_qjbj_notify(s);
00351         le_update_paletteaux_punct_notify(s);
00352 
00353         le_session_update_status_string(s, le_session_context->current_conversion_status);
00354 
00355         if (session_get_pc_aux_name(le_session_context)) {
00356             int cursor_x, cursor_y, cursor_w, cursor_h;
00357 
00358             session_get_pc_position(le_session_context, &cursor_x, &cursor_y, &cursor_w, &cursor_h);
00359 
00360             le_hide_candidates_atomic(le_session_context, 0);
00361             le_hide_preedit_atomic(le_session_context, 0);
00362             le_change_compositeaux_option_notify(le_session_context);
00363             le_update_pc_position(s, 
00364                                   session_get_pc_aux_name(le_session_context),
00365                                   cursor_x,
00366                                   cursor_y,
00367                                   cursor_w,
00368                                   cursor_h);
00369 
00370             le_update_preedit_atomic(le_session_context, &le_session_context->preedit_backup, 0);
00371             if (le_session_context->preedit_show)
00372                 le_show_preedit_atomic(le_session_context, 0);
00373 
00374             le_update_candidates_atomic(le_session_context, &le_session_context->candidates_backup, 0);
00375             if (le_session_context->candidates_show)
00376                 le_show_candidates_atomic(le_session_context, 0);
00377         }
00378 
00379         ImeModuleRec* current_ime_module = le_session_context->current_ime_module;
00380         if (current_ime_module && current_ime_module->methods  && current_ime_module->methods->ImeFocusIn)
00381             current_ime_module->methods->ImeFocusIn((ImeInputContext)le_session_context);
00382     }
00383 
00384     return (LE_OK);
00385 }
00386 
00387 LeResult le_session_set_focus_in(iml_session_t * s)
00388 {
00389     LeDesktopContextRec* le_desktop_context = (LeDesktopContextRec *)le_session_get_desktop_context(s);
00390     iml_session_t* cfs = (iml_session_t *)le_desktop_context_get_current_session(le_desktop_context); 
00391 
00392     DEBUG_printf("le_session_focus_in: switch session from 0x%x to 0x%x\n", cfs, s);
00393 
00394     if (cfs != NULL) {
00395         le_session_focus_out(cfs);
00396         le_desktop_context_set_current_session(le_desktop_context, NULL);
00397         le_desktop_context->focus_seq_wrong = ((cfs==s)?0:1);
00398     }
00399     le_session_focus_in(s);
00400     le_desktop_context_set_current_session(le_desktop_context, s);
00401 }
00402 
00403 IMText *le_session_reset(iml_session_t * s)
00404 {
00405     return ((IMText *) NULL);
00406 }
00407 
00408 /*****************************************
00409       LE Session Functions for iml_session_t
00410 *****************************************/
00411 LeDesktopContextRec *le_session_get_desktop_context(iml_session_t * s)
00412 {
00413     return ((LeDesktopContextRec *) s->desktop->specific_data);
00414 }
00415 
00416 LeSessionContextRec *le_session_get_session_context(iml_session_t * s)
00417 {
00418     return (LeSessionContextRec *)s->specific_data;
00419 }
00420 
00421 ImeModuleRec *le_session_get_ime_module_by_uuid(iml_session_t * s,
00422                                                 char *uuid)
00423 {
00424     LeDesktopContextRec *le_desktop_context = NULL;
00425     int i;
00426 
00427     le_desktop_context = (LeDesktopContextRec *) le_session_get_desktop_context(s);
00428     if (le_desktop_context == NULL || le_desktop_context->ime_modules == NULL)
00429         return (NULL);
00430 
00431     for (i = 0; i < le_desktop_context->num_ime_modules; i++) {
00432         ImeModuleRec *ime_module =
00433             le_desktop_context->ime_modules[i]->ime_module;
00434         if (!strncmp
00435             (ime_module->info->uuid, uuid, strlen(ime_module->info->uuid)))
00436             return (ime_module);
00437     }
00438     return (NULL);
00439 }
00440 
00441 ImeModuleRec *le_session_get_current_ime_module(iml_session_t * s)
00442 {
00443     LeSessionContextRec *le_session_context = NULL;
00444 
00445     le_session_context = le_session_get_session_context(s);
00446     if (le_session_context == NULL)
00447         return (NULL);
00448 
00449     return (le_session_context->current_ime_module);
00450 }
00451 
00452 ImePropertyListRec *le_session_get_current_ime_module_property_list(
00453     iml_session_t * s)
00454 {
00455     LeDesktopContextRec *le_desktop_context = NULL;
00456     LeSessionContextRec *le_session_context = NULL;
00457     ImeModuleRec *current_ime_module;
00458     ImePropertyListRec *pl;
00459     int i;
00460 
00461     le_session_context = le_session_get_session_context(s);
00462     if (le_session_context == NULL)
00463         return (NULL);
00464 
00465     current_ime_module = le_session_context->current_ime_module;
00466     if (current_ime_module == NULL)
00467         return (NULL);
00468 
00469     le_desktop_context =
00470         (LeDesktopContextRec *) le_session_get_desktop_context(s);
00471     if (le_desktop_context == NULL ||
00472         le_desktop_context->ime_modules == NULL)
00473         return (current_ime_module->info->pl);
00474 
00475     for (i = 0; i < le_desktop_context->num_ime_modules; i++) {
00476        ImeModuleContextRec *ime_module_context = le_desktop_context->ime_modules[i];
00477        if (ime_module_context == NULL)
00478            continue;
00479 
00480        if (current_ime_module == ime_module_context->ime_module) {
00481            if (ime_module_context->pl)
00482                return (ime_module_context->pl);
00483        }
00484     }
00485 
00486     return (current_ime_module->info->pl);
00487 }
00488 
00489 ImeModuleRec *le_session_get_next_ime_module(iml_session_t * s)
00490 {
00491     LeDesktopContextRec *le_desktop_context = NULL;
00492     LeSessionContextRec *le_session_context = NULL;
00493     ImeModuleRec *current_ime_module;
00494     int current_ime_id;
00495     int i;
00496 
00497     le_session_context = le_session_get_session_context(s);
00498     if (le_session_context == NULL)
00499         return (NULL);
00500 
00501     current_ime_module = le_session_context->current_ime_module;
00502     le_desktop_context =
00503         (LeDesktopContextRec *) le_session_get_desktop_context(s);
00504     if (le_desktop_context == NULL ||
00505         le_desktop_context->ime_modules == NULL)
00506         return (NULL);
00507 
00508 #if 0
00509     if (current_ime_module == NULL)
00510         return ((ImeModuleRec *)
00511                 le_desktop_context_get_default_ime_module
00512                 (le_desktop_context));
00513 #endif
00514     current_ime_id = -1;
00515     if (current_ime_module != NULL) {
00516         for (i = 0; i < le_desktop_context->num_ime_modules; i++) {
00517             if (current_ime_module ==
00518                 le_desktop_context->ime_modules[i]->ime_module) {
00519                 current_ime_id = i;
00520                 break;
00521             }
00522         }
00523     }
00524     for (i = 0; i < le_desktop_context->num_ime_modules; i++) {
00525         ImeModuleContextRec *ime_module_context;
00526         int ime_module_id;
00527 
00528         ime_module_id = current_ime_id + i + 1;
00529         ime_module_id %= le_desktop_context->num_ime_modules;
00530 
00531         ime_module_context = le_desktop_context->ime_modules[ime_module_id];
00532         if (ime_module_context->enabled)
00533             return (ime_module_context->ime_module);
00534     }
00535 
00536     return (NULL);
00537 }
00538 
00539 
00540 void le_session_switch_to_new_ime_module(iml_session_t * s, ImeModuleRec * new_ime_module)
00541 {
00542     DEBUG_printf("le_session_switch_to_new_ime_module: %x(%s)\n", 
00543                   new_ime_module, (new_ime_module)?(new_ime_module->info->uuid):"NULL");
00544 
00545     LeSessionContextRec *le_session_context = (LeSessionContextRec *)le_session_get_session_context(s);
00546 
00547     if (le_session_context == NULL) return;
00548 
00549     le_session_focus_out(s);
00550     session_detach_ime(le_session_context);
00551     session_attach_ime(le_session_context, new_ime_module);
00552     le_session_focus_in(s);
00553 
00554     return;
00555 }
00556 
00557 void le_session_switch_to_next_ime_module(iml_session_t * s)
00558 {
00559     ImeModuleRec *next_ime_module;
00560 
00561     next_ime_module = le_session_get_next_ime_module(s);
00562     le_session_switch_to_new_ime_module(s, next_ime_module);
00563     return;
00564 }
00565 
00566 LeBoolean le_session_check_if_ime_available(iml_session_t * s)
00567 {
00568     ImeModuleRec *current_ime_module =
00569         (ImeModuleRec *) le_session_get_current_ime_module(s);
00570     if (current_ime_module == NULL)
00571         return (LE_FALSE);
00572     return (LE_TRUE);
00573 }
00574 
00575 ImeEncoding le_session_get_current_ime_encoding(iml_session_t * s)
00576 {
00577     ImeModuleRec *current_ime_module =
00578         (ImeModuleRec *) le_session_get_current_ime_module(s);
00579     if (current_ime_module == NULL)
00580         return (ENCODE_INVALID);
00581     return (current_ime_module->info->encoding);
00582 }
00583 
00584 ImeEncoding le_session_get_client_encoding(iml_session_t * s)
00585 {
00586     LeSessionContextRec *le_session_context = NULL;
00587 
00588     le_session_context = le_session_get_session_context(s);
00589     if (le_session_context == NULL)
00590         return (ENCODE_UTF8);
00591 
00592     return (le_session_context->client_encoding);
00593 }
00594 
00595 LeResult le_session_set_client_encoding(iml_session_t * s,
00596                                         ImeEncoding encoding)
00597 {
00598     LeSessionContextRec *le_session_context = NULL;
00599 
00600     le_session_context = le_session_get_session_context(s);
00601     if (le_session_context == NULL)
00602         return (LE_FAIL);
00603 
00604     le_session_context->client_encoding = encoding;
00605     return (LE_OK);
00606 }
00607 
00608 QjBjStatus le_session_get_qjbj_status(iml_session_t * s)
00609 {
00610     LeSessionContextRec *le_session_context = NULL;
00611 
00612     le_session_context = le_session_get_session_context(s);
00613     if (le_session_context == NULL)
00614         return (QJBJ_HALFWIDTH);
00615 
00616     return (le_session_context->current_qjbj_status);
00617 }
00618 
00619 LeResult le_session_set_qjbj_status(iml_session_t * s,
00620                                     QjBjStatus qjbj_status)
00621 {
00622     LeSessionContextRec *le_session_context = NULL;
00623 
00624     le_session_context = le_session_get_session_context(s);
00625     if (le_session_context == NULL)
00626         return (LE_FAIL);
00627 
00628     if (qjbj_status) {
00629         le_session_context->current_qjbj_status = QJBJ_FULLWIDTH;
00630     } else {
00631         le_session_context->current_qjbj_status = QJBJ_HALFWIDTH;
00632     }
00633     return (LE_OK);
00634 }
00635 
00636 LeResult le_session_toggle_qjbj_status(iml_session_t * s)
00637 {
00638     LeSessionContextRec *le_session_context = NULL;
00639     QjBjStatus qjbj_status;
00640     ImeModuleRec *current_ime_module;
00641     ImeEventRec trigger;
00642     int result = IME_UNPROCESSED_EVENT;
00643 
00644     le_session_context =  le_session_get_session_context(s);
00645     if (le_session_context == NULL) return (LE_FAIL);
00646     qjbj_status = le_session_context->current_qjbj_status;
00647 
00648     current_ime_module = (ImeModuleRec *) le_session_get_current_ime_module(s);
00649     if (current_ime_module == NULL || current_ime_module->methods == NULL)
00650         return (LE_FAIL);
00651 
00652     trigger.notify_event.type = IME_EVENT_IMM_NOTIFY;
00653     trigger.notify_event.peer = 0; // should not be used, it is from IMM
00654     trigger.notify_event.ic = (ImeInputContext) le_session_context;
00655     trigger.notify_event.trigger = IMM_TRIGGER_FULL_HALF_SIMBOL;
00656     trigger.notify_event.value = (qjbj_status == QJBJ_FULLWIDTH) ? 0 : 1;
00657 
00658     if (current_ime_module->methods->ImeProcessUIEvent != NULL)
00659         result = current_ime_module->methods-> ImeProcessUIEvent((ImeInputContext)le_session_context, &trigger);
00660 
00661     if (result == IME_OK || result == IME_UNPROCESSED_EVENT) {
00662         if (qjbj_status == QJBJ_FULLWIDTH) {
00663             le_session_context->current_qjbj_status = QJBJ_HALFWIDTH;
00664         } else {
00665             le_session_context->current_qjbj_status = QJBJ_FULLWIDTH;
00666         }
00667         DEBUG_printf("le_session_toggle_qjbj_status: %d\n",
00668                      le_session_context->current_qjbj_status);
00669 
00670         le_update_paletteaux_qjbj_notify(s);
00671         return (LE_OK);
00672     }
00673     return LE_FAIL;
00674 }
00675 
00676 PunctStatus le_session_get_punct_status(iml_session_t * s)
00677 {
00678     LeSessionContextRec *le_session_context = le_session_get_session_context(s);
00679     if (le_session_context == NULL)
00680         return (PUNCT_ENGLISH);
00681 
00682     return (le_session_context->current_punct_status);
00683 }
00684 
00685 LeResult le_session_set_punct_status(iml_session_t * s,
00686                                      PunctStatus punct_status)
00687 {
00688     LeSessionContextRec *le_session_context = NULL;
00689 
00690     le_session_context = le_session_get_session_context(s);
00691     if (le_session_context == NULL)
00692         return (LE_FAIL);
00693 
00694     if (punct_status) {
00695         le_session_context->current_punct_status = PUNCT_CHINESE;
00696     } else {
00697         le_session_context->current_punct_status = PUNCT_ENGLISH;
00698     }
00699     return (LE_OK);
00700 }
00701 
00702 LeResult le_session_toggle_punct_status(iml_session_t * s)
00703 {
00704     LeSessionContextRec *le_session_context = NULL;
00705     PunctStatus punct_status;
00706     ImeModuleRec *current_ime_module;
00707     ImeEventRec trigger;
00708     int result = IME_UNPROCESSED_EVENT;
00709 
00710     le_session_context = le_session_get_session_context(s);
00711     if (le_session_context == NULL)
00712         return (LE_FAIL);
00713     punct_status = le_session_context->current_punct_status;
00714 
00715     current_ime_module =
00716         (ImeModuleRec *) le_session_get_current_ime_module(s);
00717     if (current_ime_module == NULL || current_ime_module->methods == NULL)
00718         return (LE_FAIL);
00719 
00720     trigger.notify_event.type = IME_EVENT_IMM_NOTIFY;
00721     trigger.notify_event.peer = 0; // should not be used, it is from IMM
00722     trigger.notify_event.ic = (ImeInputContext) le_session_context;
00723     trigger.notify_event.trigger = IMM_TRIGGER_FULL_HALF_PUNC;
00724     trigger.notify_event.value = (punct_status == PUNCT_CHINESE) ? 0 : 1;
00725 
00726     if (current_ime_module->methods->ImeProcessUIEvent != NULL)
00727         result =
00728             current_ime_module->methods->
00729             ImeProcessUIEvent((ImeInputContext) le_session_context,
00730                               &trigger);
00731     if (result == IME_OK || result == IME_UNPROCESSED_EVENT) {
00732         if (punct_status == PUNCT_CHINESE) {
00733             le_session_context->current_punct_status = PUNCT_ENGLISH;
00734         } else {
00735             le_session_context->current_punct_status = PUNCT_CHINESE;
00736         }
00737         DEBUG_printf("le_session_toggle_punct_status: %d\n",
00738                      le_session_context->current_punct_status);
00739 
00740         le_update_paletteaux_punct_notify(s);
00741         return (LE_OK);
00742     }
00743     return LE_FAIL;
00744 }
00745 
00746 ConversionStatus le_session_get_conversion_status(iml_session_t * s)
00747 {
00748     LeSessionContextRec *le_session_context = NULL;
00749 
00750     le_session_context = le_session_get_session_context(s);
00751     if (le_session_context == NULL)
00752         return (CONVERSION_OFF);
00753 
00754     return (le_session_context->current_conversion_status);
00755 }
00756 
00757 LeResult le_session_set_conversion_status(iml_session_t    *s,
00758                                           ConversionStatus  conversion_status)
00759 {
00760     LeSessionContextRec *le_session_context = NULL;
00761     ImeModuleRec *current_ime_module;
00762     ImeEventRec trigger;
00763 
00764     DEBUG_printf("le_session_set_conversion_status: %d\n", conversion_status);
00765     le_session_context = le_session_get_session_context(s);
00766     if (le_session_context == NULL) {
00767         DEBUG_printf("le_session_set_conversion_status: create session context for 0x%x\n", s);
00768         le_session_context = (LeSessionContextRec *) le_session_create(s);
00769     }
00770     if (le_session_context == NULL) return (LE_FAIL);
00771 
00772     current_ime_module = (ImeModuleRec *) le_session_get_current_ime_module(s);
00773     DEBUG_printf ("le_session_set_conversion_status: current_ime_module: %p\n", current_ime_module);
00774 
00775     if (conversion_status == CONVERSION_OFF) {
00776         DEBUG_printf("le_session_set_conversion_status(): CONVERSION_OFF\n");
00777 
00778         le_hide_paletteaux_notify(s);
00779         le_session_focus_out(s);
00780         session_detach_ime(le_session_context);
00781 
00782         le_iml_conversion_off(s);
00783 
00784     } else {
00785         DEBUG_printf("le_session_set_conversion_status(): CONVERSION_ON\n");
00786 
00787         le_iml_conversion_on(s);
00788 
00789         if (current_ime_module == NULL) {
00790             current_ime_module = le_session_get_next_ime_module(s);
00791         }
00792         session_attach_ime(le_session_context, current_ime_module);
00793 
00794         le_session_focus_in(s);
00795         le_change_paletteaux_focus_notify(s);
00796     }
00797 
00798     return (LE_OK);
00799 }
00800 
00801 LeResult le_session_toggle_conversion_status(iml_session_t * s)
00802 {
00803     LeSessionContextRec *le_session_context = NULL;
00804     ConversionStatus conversion_status;
00805     LeResult le_result;
00806 
00807     le_session_context =  le_session_get_session_context(s);
00808     if (le_session_context == NULL) return (LE_FAIL);
00809 
00810     conversion_status = le_session_context->current_conversion_status;
00811     DEBUG_printf("le_session_toggle_conversion_status: %d\n", ~conversion_status);
00812     if (conversion_status == CONVERSION_OFF) {
00813         le_result = le_session_set_conversion_status(s, CONVERSION_ON);
00814     } else {
00815         le_result = le_session_set_conversion_status(s, CONVERSION_OFF);
00816     }
00817 
00818     return (le_result);
00819 }
00820 
00821 LeResult le_session_update_status_string(iml_session_t * s,
00822                                          ConversionStatus
00823                                          conversion_status)
00824 {
00825     UTFCHAR tmp_buf[128];
00826     UTFCHAR *tmp_ptr = tmp_buf;
00827     int from_len, to_left, ret;
00828 
00829     unsigned char *status_str = English_Status_UTF;
00830     ImeEncoding encoding = ENCODE_UTF8;
00831 
00832     if (s == NULL)
00833         return (LE_FAIL);
00834 
00835     if (conversion_status == CONVERSION_ON) {
00836         ImeModuleRec *current_ime_module;
00837 
00838         current_ime_module = le_session_get_current_ime_module(s);
00839         if (current_ime_module != NULL) {
00840 /*
00841             encoding = current_ime_module->info->encoding;
00842             status_str = (unsigned char *)current_ime_module->info->name;
00843 */
00844             status_str = Chinese_Status_UTF;
00845         }
00846     }
00847 
00848     if (!status_str || !*status_str)
00849         return (LE_FAIL);
00850 
00851     from_len = strlen(status_str);
00852     to_left = 128;
00853     memset(tmp_buf, 0, sizeof(UTFCHAR) * 128);
00854     ret = Convert_Native_To_UTF16(encoding,
00855                                   status_str,
00856                                   from_len,
00857                                   (char **) &tmp_ptr,
00858                                   (size_t *) & to_left);
00859     if (ret == -1)
00860         return (LE_FAIL);
00861 
00862     le_iml_status_start(s);
00863     le_iml_status_draw(s, tmp_buf);
00864     return (LE_OK);
00865 }
00866 
00867 LeResult le_session_set_as_desktop_current_session(iml_session_t * s)
00868 {
00869     LeDesktopContextRec *le_desktop_context = NULL;
00870 
00871     le_desktop_context =
00872         (LeDesktopContextRec *) le_session_get_desktop_context(s);
00873     le_desktop_context_set_current_session(le_desktop_context, s);
00874 
00875     return (LE_OK);
00876 }
00877 
00878 LeResult session_proc_style_change(iml_session_t* s, int* pvstyle)
00879 {
00880     LeSessionContextRec *le_session_context = le_session_get_session_context(s);
00881     if (le_session_context && session_get_pc_style(le_session_context)) {
00882         DEBUG_printf("******************************pc style changed, got it***********\n");
00883         *session_get_pc_style(le_session_context) = *(TImePCAuxOption*)pvstyle;
00884         le_change_compositeaux_option_notify(le_session_context);
00885     }
00886 }
00887 
00888 LeResult session_proc_pc_move(iml_session_t* s, int x, int y, int w, int h)
00889 {
00890     LeSessionContextRec *le_session_context = le_session_get_session_context(s);
00891     if (le_session_context) {
00892         session_set_pc_position(le_session_context, x, y, w, h);
00893     }
00894 }
00895 
00896 LeResult session_proc_candidate_selection(iml_session_t*s, int idx)
00897 {
00898     ImeEventRec event;
00899     ImeModuleRec *ime = NULL;
00900     LeSessionContextRec *le_session_context = le_session_get_session_context(s);
00901 
00902     int result = IME_UNPROCESSED_EVENT;
00903     if (le_session_context)
00904         ime = le_session_context->current_ime_module;
00905 
00906     if (ime && ime->methods && ime->methods->ImeProcessUIEvent) {
00907         event.type              = IME_EVENT_CANDI_SELECT;
00908         event.any_event.peer    = 0;      // should not be used, it is from IMM
00909         event.any_event.ic      = (ImeInputContext)le_session_context;
00910         event.any_event.param   = idx;
00911 
00912         result = ime->methods-> ImeProcessUIEvent((ImeInputContext)le_session_context, &event);
00913     }
00914 
00915     /* try to fake key_press if IME do not process it */
00916     if (result == IME_UNPROCESSED_EVENT && ime && ime->methods && ime->methods->ImeProcessKeyEvent) {
00917         char c = 0;
00918         ImeCandidatesRec *pcs = &le_session_context->candidates_backup;
00919         if (pcs->numbers != NULL) {
00920             c = pcs->numbers[idx];
00921         } else if (idx < 9) {
00922             c = '1' + idx;
00923         } else if (idx == 9) {
00924             c = '0';
00925         } else if (idx < 16) {
00926             c = 'A' + idx - 10;
00927         }
00928         if (c != 0) {
00929             ImeKeyRec key = {c, c, 0, 0};
00930             result = ime->methods->ImeProcessKeyEvent((ImeInputContext)le_session_context, &key);
00931         }
00932     }
00933 
00934     return LE_OK;
00935 }
00936 
00937 LeResult session_proc_candidate_page(iml_session_t* s, int pgop)
00938 {
00939     ImeEventRec event;
00940     ImeModuleRec* ime;
00941     LeSessionContextRec *le_session_context = le_session_get_session_context(s);
00942 
00943     int result = IME_UNPROCESSED_EVENT;
00944     if (le_session_context)
00945         ime = le_session_context->current_ime_module;
00946 
00947     if (ime && ime->methods && ime->methods->ImeProcessUIEvent) {
00948         event.type              = IME_EVENT_CANDI_PAGE;
00949         event.any_event.peer    = 0;      // should not be used, it is from IMM
00950         event.any_event.ic      = (ImeInputContext)le_session_context;
00951         event.any_event.param   = pgop;
00952         result = ime->methods-> ImeProcessUIEvent((ImeInputContext)le_session_context, &event);
00953     }
00954 
00955     if (result == IME_UNPROCESSED_EVENT && ime && ime->methods && ime->methods->ImeProcessKeyEvent) {
00956         ImeKeyRec key = {0, 0, 0, 0};
00957         switch (pgop) {
00958         case 1: //prev page
00959             key.keycode = IME_VK_PAGE_UP; break;
00960         case 2: //next page
00961             key.keycode = IME_VK_PAGE_DOWN; break;
00962         }
00963         if (key.keycode != 0)
00964             result = ime->methods->ImeProcessKeyEvent((ImeInputContext)le_session_context, &key);
00965     }
00966 
00967     return LE_OK;
00968 }
00969 
00970