Back to index

im-sdk  12.3.91
le_proc.c
Go to the documentation of this file.
00001 /*
00002  * Copyright 2003 Sun Microsystems Inc.
00003  *
00004  * This is free software; you can redistribute it and/or
00005  * modify it under the terms of the GNU Lesser General Public
00006  * License as published by the Free Software Foundation; either
00007  * version 2 of the License, or (at your option) any later version.
00008  *
00009  * This library is distributed in the hope that it will be useful,
00010  * but WITHOUT ANY WARRANTY; without even the implied warranty of
00011  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
00012  * Lesser General Public License for more details.
00013  *
00014  * You should have received a copy of the GNU Lesser General Public
00015  * License along with this library; if not, write to the
00016  * Free Software Foundation, Inc., 59 Temple Place - Suite 330,
00017  * Boston, MA 02111-1307, USA.
00018  *
00019  * Authors: Karl Park <karl.park@sun.com>
00020  */
00021 
00022 #ifdef HAVE_CONFIG_H
00023 #include <config.h>
00024 #endif
00025 
00026 #include <stdio.h>
00027 #include <stdlib.h>
00028 #include <string.h>
00029 #include <strings.h>
00030 #include <assert.h>
00031 
00032 #include "le_proc.h"
00033 #include "koinput.h"
00034 #include "le.h"
00035 #include "iml.h"
00036 #include "encode.h"
00037 #include "method.h"
00038 #include "kolelog.h"
00039 
00040 extern unsigned char English_Status_UTF[];
00041 extern int           g_number_of_engines;
00042 extern IMEEngineRec  *g_engines[MAX_ENGINE_NUM];
00043 
00044 static int get_keyboard_string(keyboard_layout id, char **keyboard_str_return);
00045 static int get_hex_string(iml_session_t *s, char **hex_string_return);
00046 static int get_symbol_string(char **symbol_string_return);
00047 static int get_hanja_string(char **hanja_string_return);
00048 
00049 /* output input method buffer to system */
00050 void
00051 le_output_ime_buffer (iml_session_t *s, IMEBuffer ime_buffer,
00052                     IMEKeyEventStruct  *ime_keyevent)
00053 {
00054   MyDataPerSession *session_data = (MyDataPerSession *) s->specific_data;
00055   MyDataPerDesktop *desktop_data = (MyDataPerDesktop *)(s->desktop->specific_data);
00056   IMEBufferMethods mthds = session_data->session_core.ime_methods_table;
00057   IMEBufferWhatToDo *task_list = NULL;
00058 
00059   int current_engine_id = 0;
00060   IMEEngine p_current_engine;
00061   Bool result_is_okay = True;
00062   Bool method_return;
00063                                                                                
00064   UTFCHAR *status_string = NULL;
00065   UTFCHAR *preedit_string = NULL;
00066   UTFCHAR **lookup_string_list = NULL;
00067   UTFCHAR *commit_string = NULL;
00068   int n_candidates;
00069   int i_current_candidate;
00070   
00071   p_current_engine = g_engines[current_engine_id];
00072 
00073   method_return = (*mthds->ime_buffer_get_what_to_do) (ime_buffer,&task_list);
00074   assert (method_return == True);
00075   if (method_return != True){
00076     fprintf (stderr, "le_output_ime_buffer erroro: cannot get todo list\n");
00077     return;
00078   }
00079 
00080   if (task_list->do_status) {
00081     result_is_okay = 
00082       (*mthds->ime_buffer_get_status) (ime_buffer, &status_string);
00083     assert (result_is_okay == True);
00084     
00085     if (result_is_okay == True) {
00086       iml_status_draw (s);
00087       free (status_string);
00088     }
00089   }
00090 
00091   if (task_list->do_commit) {
00092     result_is_okay = 
00093       (*mthds->ime_buffer_get_commit_string) (ime_buffer, &commit_string);
00094     if (result_is_okay == True) {
00095       iml_preedit_enddraw (s);
00096       iml_commit (s, commit_string);
00097       task_list->do_commit = False;
00098 
00099       /*
00100        s->If->m->iml_make_preedit_erase_inst (s);
00101       */
00102       free (commit_string);
00103       commit_string = 0x0;
00104       }
00105   }
00106 
00107   if (task_list->do_preedit) {
00108     result_is_okay = 
00109       (*mthds->ime_buffer_get_preedit) (ime_buffer, &preedit_string);
00110     assert (result_is_okay == True);
00111     
00112     if (result_is_okay == True) {
00113       iml_preedit_draw (s, preedit_string, -1);
00114       free (preedit_string);
00115     } else {
00116       iml_inst *lp;
00117       lp = (iml_inst *)s->If->m->iml_make_lookup_done_inst (s);
00118       s->If->m->iml_execute (s, &lp);
00119     }
00120   }
00121 
00122   if (task_list->do_lookup) {
00123     result_is_okay = 
00124       (*mthds->ime_buffer_get_candidates) (ime_buffer,
00125                                       &n_candidates,
00126                                       &i_current_candidate,
00127                                       &lookup_string_list);
00128 
00129     if (result_is_okay == True)
00130       iml_lookup_draw (s,
00131                      lookup_string_list,
00132                      n_candidates, i_current_candidate, NUMERIC_LABEL);
00133       
00134   } else {
00135     iml_inst *lp;
00136     iml_inst *rrv = NULL;
00137     lp = s->If->m->iml_make_lookup_done_inst(s);
00138     s->If->m->iml_link_inst_tail (&rrv, lp);
00139     s->If->m->iml_execute (s, &rrv);
00140   }
00141 
00142     
00143 
00144   if (task_list->do_sendback && ime_keyevent)
00145     {
00146       iml_sendback_key(s, ime_keyevent);
00147       task_list->do_sendback = False;
00148     }
00149   (*mthds->ime_buffer_set_what_to_do) (ime_buffer, task_list);
00150   free (task_list);
00151 }
00152        
00153    
00154 
00155 
00156 /* return:
00157        0 - success
00158        -1 - error(memory allocation)
00159    in: keyboard_layout_id
00160    out: keyboard_str_return encoded in utf-8
00161 */
00162 
00163 static int get_keyboard_string(keyboard_layout id, char **keyboard_str_return)
00164 {
00165        int ret;
00166        size_t ilen, olen;
00167        char inbuffer[256], outbuffer[256];
00168        char *tbuf;
00169        char *key_str;
00170 
00171        switch(id){
00172        case KEYBOARD_LAYOUT_2BEOLSIK:
00173               key_str= (char *)strdup(KEYBOARD_2BEOLSIK);
00174               break;
00175        case KEYBOARD_LAYOUT_3BEOLSIK_390:
00176               key_str = (char *)strdup(KEYBOARD_3BEOLSIK_390);
00177               break;
00178        case KEYBOARD_LAYOUT_3BEOLSIK_FINAL:
00179               key_str = (char *)strdup(KEYBOARD_3BEOLSIK_FINAL);
00180               break;
00181        default:
00182               key_str = (char *)strdup(KEYBOARD_2BEOLSIK);
00183               break;
00184        }
00185        if(NULL == key_str){ /* memory allocation error */
00186               return -1;
00187        }
00188        
00189        bzero(inbuffer, 256); bzero(outbuffer, 256);
00190        strcpy(inbuffer, key_str);
00191        ilen = strlen(inbuffer), olen = 256;
00192        tbuf = outbuffer;
00193 
00194        ret = Convert_Native_To_UTF8(ENCODE_EUC_KO,inbuffer, ilen, &tbuf, &olen);
00195 
00196        assert(ret != -1);
00197        *keyboard_str_return = (char *)strdup(outbuffer);
00198        if(NULL == *keyboard_str_return)
00199               return -1;
00200        return 0;
00201 
00202 }
00203 #if 0
00204 
00205 static int get_hex_string(iml_session_t *s, char **hex_string_return)
00206 {
00207        int ret;
00208        size_t ilen, olen;
00209        char inbuffer[256], outbuffer[256];
00210        char *tbuf;
00211        MyDataPerSession *session_data = (MyDataPerSession *) s->specific_data;
00212 
00213        bzero(inbuffer, 256); bzero(outbuffer, 256);
00214        if(session_data->ime_buffer->triggered_conversion_key == ctrl_x){
00215               strcpy(inbuffer, INPUT_MODE_HEX_IN_EUC_STR);
00216        }
00217        else if(session_data->ime_buffer->triggered_conversion_key == ctrl_shift_x){
00218               strcpy(inbuffer, INPUT_MODE_HEX_IN_UTF8_STR);
00219        }
00220 
00221        ilen = strlen(inbuffer), olen = 256;
00222        tbuf = outbuffer;
00223 
00224        ret = Convert_Native_To_UTF8(ENCODE_EUC_KO,inbuffer, ilen, &tbuf, &olen);
00225 
00226        assert(ret != -1);
00227        *hex_string_return = (char *)strdup(outbuffer);
00228 }
00229 #endif
00230 
00231 static int get_symbol_string(char **symbol_string_return)
00232 {
00233        int ret;
00234        size_t ilen, olen;
00235        char inbuffer[256], outbuffer[256];
00236        char *tbuf;
00237 
00238        bzero(inbuffer, 256); bzero(outbuffer, 256);
00239        strcpy(inbuffer, INPUT_MODE_SYMBOL_STR);
00240        ilen = strlen(inbuffer), olen = 256;
00241        tbuf = outbuffer;
00242 
00243        ret = Convert_Native_To_UTF8(ENCODE_EUC_KO,inbuffer, ilen, &tbuf, &olen);
00244 
00245        assert(ret != -1);
00246 
00247        *symbol_string_return = (char *)strdup((const char *) &outbuffer[0]);
00248 
00249        return 0;
00250 }
00251 
00252 static int get_hanja_string(char **hanja_string_return)
00253 {
00254        int ret;
00255        size_t ilen, olen;
00256        char inbuffer[256], outbuffer[256];
00257        char *tbuf;
00258 
00259        bzero(inbuffer, 256); bzero(outbuffer, 256);
00260        strcpy(inbuffer, INPUT_MODE_HANJA_STR);
00261        ilen = strlen(inbuffer), olen = 256;
00262        tbuf = outbuffer;
00263 
00264        ret = Convert_Native_To_UTF8(ENCODE_EUC_KO,inbuffer, ilen, &tbuf, &olen);
00265 
00266        assert(ret != -1);
00267        *hanja_string_return = (char *)strdup(outbuffer);
00268        return 0;
00269        
00270 }
00271 
00272 void
00273 le_switch_engine(iml_session_t *s, int engine_id)
00274 {
00275 #if 0
00276   int engine_id, i;
00277   char locale_id, system_locale_id;
00278   IMEBufferMethods ime_methods;
00279 
00280   Bool result_is_good;
00281   MyDataPerSession *session_data = (MyDataPerSession *) s->specific_data;
00282 
00283   if (engine_id >= g_number_of_engines)  
00284     engine_id = 0xff;
00285 
00286   if (engine_id != 0xff && 
00287       g_engines[engine_id]->core.baseinfo.status == ENGINE_NOT_INSTALLED)
00288     engine_id = 0xff;
00289 
00290   if (engine_id != 0xff) {
00291     result_is_good =
00292       g_engines[engine_id]->so_methods->ime_buffer_initialize(
00293                                                        &g_engines[engine_id]->core,
00294                                                        session_data->ime_buffer);
00295               
00296     KOLE_LOG (LOGDEST_STDOUT,
00297              "start aux window and IME_SessionInit return :%d\n", ret);
00298     if (result_is_good == False)
00299       engine_id = 0xff;
00300   }
00301 
00302   session_data->paletteaux_status.engine_id = engine_id;
00303   le_status_draw(s);
00304   le_update_keymapinfo_notify(s, engine_id);
00305 #endif
00306 }
00307 
00308 void le_update_ime_buffer(iml_session_t *s, UserPreference *pref)
00309 {
00310 #if 0
00311        MyDataPerSession *sd = (MyDataPerSession *) s->specific_data;
00312        MyDataPerDesktop *dd = (MyDataPerDesktop *)(s->desktop->specific_data);
00313        IMEBuffer ime_buffer = sd->ime_buffer;
00314 
00315        ime_buffer->ime_user_id = pref->ime_user_id;
00316 
00317        if(pref->ime_user_home){
00318               if(ime_buffer->ime_user_home)
00319                      free(ime_buffer->ime_user_home);
00320               ime_buffer->ime_user_home = strdup(pref->ime_user_home);
00321        }
00322        ime_buffer->keyboard_layout = pref->keyboard_layout;
00323        ime_buffer->conversion_format = pref->conversion_format;
00324        /* ime_buffer->delete_by_jaso = pref->delete_by_jaso; */
00325        ime_buffer->auto_commit_on_char_basis = pref->auto_commit_on_char_basis;
00326        ime_buffer->auto_commit_on_single_candidate_conversion = pref->auto_commit_on_single_candidate_conversion;
00327 #endif
00328 }
00329