Back to index

im-sdk  12.3.91
le.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 <strings.h>
00029 
00030 #include "koinput.h"
00031 #include "kole.h"
00032 #include "le.h"
00033 #include "le_proc.h"
00034 #include "iml.h"
00035 #include "method.h"
00036 #include "xaux_locale.h"
00037 #include "key_event.h"
00038 #include "kolelog.h"
00039 
00040 Bool if_le_OpenIF (iml_if_t *);
00041 Bool if_le_CloseIF (iml_if_t *);
00042 Bool if_le_GetIFValue (iml_if_t *, IMArgList, int);
00043 Bool if_le_SetIFValue (iml_if_t *, IMArgList, int);
00044 Bool if_le_OpenDesktop (iml_desktop_t *, IMArgList, int);
00045 Bool if_le_CloseDesktop (iml_desktop_t *);
00046 Bool if_le_CreateSC (iml_session_t *, IMArgList, int);
00047 Bool if_le_DestroySC (iml_session_t *);
00048 Bool if_le_GetSCValue (iml_session_t *, IMArgList, int);
00049 Bool if_le_SetSCValue (iml_session_t *, IMArgList, int);
00050 IMText *if_le_ResetSC (iml_session_t *);
00051 void if_le_SetSCFocus (iml_session_t *);
00052 void if_le_UnsetSCFocus (iml_session_t *);
00053 void if_le_SendEvent (iml_session_t *, IMInputEvent * ev);
00054 
00055 /* IF Method */
00056 if_methods_t le_methods = {
00057   if_le_OpenIF,
00058   if_le_CloseIF,
00059   if_le_GetIFValue,
00060   if_le_SetIFValue,
00061   if_le_OpenDesktop,
00062   if_le_CloseDesktop,
00063   if_le_CreateSC,
00064   if_le_DestroySC,
00065   if_le_GetSCValue,
00066   if_le_SetSCValue,
00067   if_le_ResetSC,
00068   if_le_SetSCFocus,
00069   if_le_UnsetSCFocus,
00070   if_le_SendEvent
00071 };
00072 
00073 extern char lename_string[];
00074 extern UTFCHAR lename_utf_string[];
00075 extern IMLocale locales[];
00076 extern char default_locale_id;
00077 
00078 extern int           g_number_of_engines;
00079 extern int           g_default_engine_id;
00080 extern IMEEngineRec *g_engines[MAX_ENGINE_NUM];
00081 
00082 static IMLEName lename = {lename_string, lename_utf_string };
00083 static IMObjectDescriptorStruct *objects = NULL;
00084 
00085 static int s_id[MAX_SESSION];
00086 
00087 /* create an IM Object instantance */
00088 void
00089 objects_init ()
00090 {
00091   char xaux_so_path[125];
00092   IMObjectDescriptorStruct *l;
00093 
00094   KOLE_LOG (LOGDEST_STDOUT, "init objects, objects:%x\n", objects);
00095 
00096   if (objects != NULL) return;
00097 
00098   objects = (IMObjectDescriptorStruct *) calloc(2, sizeof(IMObjectDescriptorStruct));
00099   if (objects == NULL) return;
00100 
00101   sprintf(xaux_so_path, "./%s/auxiliary_windows/aux.so","kole");
00102   l = objects;
00103   l->leid = lename_string;                   /* engine id */
00104   l->type = IM_DOWNLOADINGOBJECT_BINGUI_TYPE; /* object type */
00105   l->name = lename_utf_string;                   
00106   l->name_length = UTFCHARLen(lename_utf_string);
00107   l->domain = "com.sun";
00108   l->scope = lename_string;
00109   l->path = (char *)(strdup(xaux_so_path));    /* path for .so from /usr/lib/iiim/ */
00110   l->signature = "";
00111   l->basepath = NULL;         /* only for CCDEF */
00112   l->encoding = NULL;         /* only for CCDEF */
00113 }
00114 
00115 void
00116 objects_done()
00117 {
00118   KOLE_LOG (LOGDEST_STDOUT, "free objects\n");
00119 
00120   if (objects == NULL) return;
00121 
00122   if (objects[0].path) free((char *)(objects[0].path));
00123   free(objects);
00124   objects = NULL;
00125 }
00126 
00127 /* htt_server get the IF information when start htt_server */
00128 void
00129 if_GetIfInfo (IMArgList args, int num_args)
00130 {
00131   int i;
00132 
00133   KOLE_LOG (LOGDEST_STDOUT, "if_GetIfInfo == num_args:%d\n", num_args);
00134 
00135   objects_init(); 
00136   for (i = 0; i < num_args; i++, args++) {
00137     switch (args->id)
00138       {
00139       case IF_VERSION:
00140        args->value = (IMArgVal) "1.2";
00141        break;
00142       case IF_LE_NAME:
00143        args->value = (IMArgVal) & lename;
00144        break;
00145       case IF_SUPPORTED_LOCALES:
00146        /* List of supported locales */
00147        args->value = (IMArgVal) & locales;
00148        break;
00149       case IF_SUPPORTED_OBJECTS:
00150        args->value = (IMArgVal) objects; 
00151        break;
00152       case IF_METHOD_TABLE:
00153        args->value = (IMArgVal) & le_methods;
00154        break;
00155       case IF_NEED_THREAD_LOCK:
00156        args->value = (IMArgVal) True;
00157        break;
00158       default:
00159        break;
00160       }
00161   }
00162 }
00163 
00164 unsigned int le_openif_counter = 0;
00165 
00166 Bool 
00167 if_le_OpenIF (iml_if_t * If)
00168 {
00169   int ret = 0;
00170   
00171   KOLE_LOG (LOGDEST_STDOUT, "if_le_OpenIF ====\n");
00172 
00173   le_openif_counter++;
00174   if (le_openif_counter > 1) return True;
00175 
00176   ret = koinput_init();
00177 
00178   /* if ret == -1, this means, there's no language engine... */
00179   if (ret == -1)
00180     return False;
00181   else
00182     return True;
00183 }
00184 
00185 /* Close the IF interface */
00186 Bool
00187 if_le_CloseIF (iml_if_t * If)
00188 {
00189   KOLE_LOG (LOGDEST_STDOUT, "if_le_CloseIF === \n");
00190   if (le_openif_counter > 0)
00191     le_openif_counter--;
00192   if (le_openif_counter == 0) {
00193     objects_done();
00194     koinput_done();
00195   }
00196   return True;
00197 }
00198 
00199 Bool
00200 if_le_GetIFValue (iml_if_t * If, IMArgList args, int num_args)
00201 {
00202   KOLE_LOG (LOGDEST_STDOUT, "if_le_GetIFValue()\n");
00203   return True;
00204 }
00205 
00206 Bool
00207 if_le_SetIFValue (iml_if_t * If, IMArgList args, int num_args)
00208 {
00209   KOLE_LOG (LOGDEST_STDOUT, "if_le_SetIFValue()\n");
00210   return True;
00211 }
00212 
00213 Bool
00214 if_le_OpenDesktop (iml_desktop_t * desktop, IMArgList args, int num_args)
00215 {
00216   MyDataPerDesktop *desktop_data = (MyDataPerDesktop *)calloc(1,sizeof(MyDataPerDesktop));
00217   int i;
00218 
00219   KOLE_LOG (LOGDEST_STDOUT, "if_le_OpenDesktop()\n");
00220 
00221   desktop_data->selectaux_started = False;
00222   desktop_data->optionaux_started = False;
00223   desktop_data->keyboardaux_started = False;
00224   desktop_data->lookupaux_started = False;
00225   desktop_data->actionaux_started = False;
00226   desktop_data->paletteaux_started = False;
00227   desktop_data->paletteaux_first_trigger_on = True;
00228   desktop_data->paletteaux_ready = False;
00229   desktop_data->current_session = 0;
00230   desktop_data->root_session = 0;
00231   desktop_data->aux_locale_id = default_locale_id;
00232 
00233   /* Initialize UserPreference data by default value.
00234      This values will be overwritten by
00235      either user preference file or aux event.
00236   */
00237   desktop_data->user_pref.ime_user_id = 0;
00238   desktop_data->user_pref.ime_user_home = NULL;
00239   desktop_data->user_pref.keyboard_layout = 0;
00240   desktop_data->user_pref.conversion_format = 0;
00241   /* desktop_data->user_pref.delete_by_jaso = 0; */
00242   
00243   desktop_data->user_pref.auto_commit_on_char_basis = 0;
00244   desktop_data->user_pref.auto_commit_on_single_candidate_conversion = 0;
00245        
00246   for (i=0; i<MAX_ENGINE_NUM; i++) {
00247     desktop_data->ime_args[i] = (IMEArgList) NULL;
00248     desktop_data->bSentKeymapToAux[i] = False;
00249   }
00250 
00251   desktop->specific_data = (void *) desktop_data;
00252 
00253   return True;
00254 }
00255 
00256 Bool
00257 if_le_CloseDesktop (iml_desktop_t * desktop)
00258 {
00259   MyDataPerDesktop *desktop_data = (MyDataPerDesktop *) desktop->specific_data;
00260   int i;
00261 
00262   KOLE_LOG (LOGDEST_STDOUT, "if_le_CloseDesktop()\n");
00263   for (i=0; i<MAX_ENGINE_NUM; i++) {
00264     if (desktop_data->ime_args[i] != (IMEArgList) NULL)
00265       free((char *)desktop_data->ime_args[i]);
00266   }
00267   if(desktop_data->user_pref.ime_user_home)
00268     free((void *)desktop_data->user_pref.ime_user_home);
00269 
00270   free(desktop_data);
00271 
00272   return True;
00273 }
00274 
00275 Bool
00276 if_le_CreateSC (iml_session_t *s, IMArgList args, int num_args)
00277 {
00278   static int first_create = 1;
00279   int current_engine_id = g_default_engine_id;
00280   IMEEngine p_current_engine;
00281   IMEBufferMethods engine_methods_table;
00282        
00283   int i, session_id;
00284   iml_desktop_t *desktop = s->desktop;
00285   MyDataPerDesktop *desktop_data = (MyDataPerDesktop *) desktop->specific_data;
00286   MyDataPerSession *p = (MyDataPerSession *) calloc(1, sizeof(MyDataPerSession));
00287 
00288   KOLE_LOG (LOGDEST_STDOUT, "if_le_CreateSC()\n");
00289 
00290   if (first_create) {
00291     for (i = 0 ;i < MAX_SESSION ;i++)
00292       s_id[i] = 0;
00293     first_create = 0;
00294   }
00295 
00296   session_id = 0;
00297   for (i=0;i< MAX_SESSION;i++)
00298     if (s_id[i]==0) { 
00299       session_id = i; 
00300       break;
00301     }
00302   s_id[session_id] = 1;
00303 
00304   desktop_data->current_session = 0;
00305   p->paletteaux_status.x = 0;
00306   p->paletteaux_status.y = 0;
00307   p->paletteaux_status.on = False;
00308   p->paletteaux_status.junjabanja = False;
00309   p->paletteaux_status.punct = False;
00310   /* p->paletteaux_status.engine_id = 0xff; */
00311   /* At this juncture, engine_id is always 0, becuase there's only one engine for ko */
00312   p->paletteaux_status.engine_id = current_engine_id;
00313     
00314   p->keyboardaux_status.x = 0;
00315   p->keyboardaux_status.y = 0;
00316   p->keyboardaux_status.keyboard_id = -1;
00317   p->keyboardaux_status.key_status = 0;
00318 
00319   p->lookupaux_status.on = False;
00320   p->selectaux_status.on = False;
00321   p->optionaux_status.on = False;
00322 
00323   p->input_mode = INPUT_MODE_ENGLISH;
00324        
00325   p_current_engine = g_engines[current_engine_id];
00326   p->p_engine = p_current_engine;
00327   engine_methods_table = p_current_engine->so_methods;
00328   p->session_core.ime_methods_table = engine_methods_table;
00329   (*engine_methods_table->ime_buffer_new)(&p->session_core.ime_buffer, session_id, current_engine_id);
00330 
00331   s->specific_data = (void*) p;
00332 
00333   /* set aux proxy data */
00334   p->protocol_type = UNKNOWN_IMP;
00335   p->client_type = UNKNOWN_CLIENT;
00336   for (i = 0; i < num_args; i++, args++) {
00337     switch (args->id) {
00338     case UI_PROTOCOL_TYPE:
00339       if (args->value) {
00340        KOLE_LOG (LOGDEST_STDOUT,
00341                 "UI_PROTOCOL_TYPE: value: %s\n", args->value);
00342        if (!strcmp (UI_PROTOCOL_TYPE_XIMP, args->value))
00343          p->protocol_type = XIMP;
00344       }
00345       break;
00346     case UI_CLIENT_TYPE:
00347       if (args->value) {
00348        KOLE_LOG (LOGDEST_STDOUT,
00349                 "UI_CLIENT_TYPE: value: %s\n", args->value);
00350        if (!strcmp (UI_CLIENT_TYPE_X, args->value))
00351          p->client_type = X11_CLIENT;
00352       }
00353       break;
00354     }
00355   }
00356   return True;
00357 }
00358 
00359 Bool
00360 if_le_DestroySC (iml_session_t * s)
00361 {
00362   int current_engine_id = 0;
00363   IMEEngine p_current_engine;
00364   IMEBufferMethods engine_methods_table;
00365   IMEBuffer p_ime_buffer;
00366   int i, session_id;
00367   iml_desktop_t *desktop;
00368   MyDataPerDesktop *desktop_data;
00369   MyDataPerSession *p;
00370   
00371   p_current_engine = g_engines[current_engine_id];
00372   engine_methods_table = p_current_engine->so_methods;
00373   desktop = s->desktop;
00374 
00375   desktop_data = (MyDataPerDesktop *) desktop->specific_data;
00376   p = (MyDataPerSession *) s->specific_data;
00377   p_ime_buffer = p->session_core.ime_buffer;
00378 
00379   KOLE_LOG (LOGDEST_STDOUT, "if_le_DestroySC(s=%x)\n", s);
00380 
00381   (*engine_methods_table->ime_buffer_conversion_end)(p_ime_buffer);
00382   if (p->paletteaux_status.on) {
00383     p->paletteaux_status.on = False;
00384     le_change_focus_notify(s);
00385   }
00386 
00387   desktop_data->current_session = 0;
00388 
00389   if (!(*engine_methods_table->ime_buffer_get_session_id)(p_ime_buffer , &session_id))
00390     return False;
00391 
00392   s_id[session_id] = 0;
00393   keyevent_switch_conversion_handler(s, CONVERSION_OFF);
00394 
00395   (*engine_methods_table->ime_buffer_free) (p->session_core.ime_buffer);
00396 
00397   free((char *) p);
00398   
00399   return True;
00400 }
00401 
00402 Bool
00403 if_le_GetSCValue (iml_session_t * s, IMArgList args, int num_args)
00404 {
00405   KOLE_LOG (LOGDEST_STDOUT, "if_le_GetSCValue(s=%x)\n\n", s);
00406   return True;
00407 }
00408 
00409 Bool
00410 if_le_SetSCValue (iml_session_t * s, IMArgList args, int num_args)
00411 {
00412   int i;
00413   IMArg *p = args;
00414   MyDataPerDesktop *desktop_data =
00415     (MyDataPerDesktop *)(s->desktop->specific_data);
00416   MyDataPerSession *ds = (MyDataPerSession *)(s->specific_data);
00417   IMEBufferMethods mthds = ds->session_core.ime_methods_table;
00418   IMEBuffer ime_buffer = ds->session_core.ime_buffer;
00419 
00420   KOLE_LOG (LOGDEST_STDOUT, "if_le_SetSCValue(), s:0x%x\n", s);
00421 
00422   desktop_data->current_session = s;
00423 
00424   for (i = 0; i < num_args; i++, p++) {
00425     switch (p->id) {
00426     case SC_TRIGGER_ON_NOTIFY:
00427       KOLE_LOG (LOGDEST_STDOUT, "SC_TRIGGER_ON_NOTIFY\n");
00428       keyevent_switch_conversion_handler (s, CONVERSION_ON);
00429       break;
00430 
00431     case SC_TRIGGER_OFF_NOTIFY:
00432       KOLE_LOG (LOGDEST_STDOUT, "SC_TRIGGER_OFF_NOTIFY\n");
00433       keyevent_switch_conversion_handler (s, CONVERSION_OFF);
00434       break;
00435                 
00436     case SC_REALIZE:
00437       if (desktop_data->paletteaux_started == False) {
00438        iml_aux_start(s, XAUX_PALETTE_CLASS_NAME);
00439        auxhandler_send_session_property (s, XAUX_PALETTE_CLASS_NAME);
00440        desktop_data->paletteaux_started = True;
00441       }
00442 
00443 
00444       iml_status_draw (s);
00445       le_change_focus_notify(s);
00446       break;
00447 
00448     default:
00449       break;
00450     }
00451   }
00452   return True;
00453 }
00454 
00455 IMText *
00456 if_le_ResetSC (iml_session_t * s)
00457 {
00458   KOLE_LOG (LOGDEST_STDOUT, "if_le_ResetSC(s=%x)\n\n", s);
00459   return (IMText *) NULL;
00460 }
00461 
00462 void
00463 if_le_SetSCFocus (iml_session_t * s)
00464 {
00465   MyDataPerDesktop *desktop_data =
00466     (MyDataPerDesktop *)(s->desktop->specific_data);
00467 
00468   KOLE_LOG (LOGDEST_STDOUT, "if_le_SetSCFocus() s:%x, current_session:%x\n",
00469        s, desktop_data->current_session);
00470 
00471   desktop_data->current_session = s;
00472 
00473   iml_status_draw (s);
00474   le_change_focus_notify(s);
00475 }
00476 
00477 void
00478 if_le_UnsetSCFocus (iml_session_t * s)
00479 {
00480   KOLE_LOG (LOGDEST_STDOUT, "if_le_UnsetSCFocus() s:%x\n", s);
00481 }
00482 
00483 void
00484 if_le_SendEvent (iml_session_t * s, IMInputEvent * ev)
00485 {
00486   MyDataPerDesktop *dd = (MyDataPerDesktop *)(s->desktop->specific_data);
00487   MyDataPerSession *sd = (MyDataPerSession *)(s->specific_data);
00488   iml_session_t *s1;
00489 
00490   KOLE_LOG (LOGDEST_STDOUT, "if_le_SendEvent session=%x\n", s);
00491   
00492   if (ev) {
00493     if (ev->type == IM_EventKeyList) {
00494       KOLE_LOG (LOGDEST_STDOUT, "Keyboard Event\n");
00495       keyevent_handler (s, (IMKeyListEvent *)ev);
00496     } else if (ev->type == IM_EventAux) {
00497       KOLE_LOG (LOGDEST_STDOUT, "Aux Event\n");
00498       s1 = dd->current_session;
00499       if (!s1) s1 = s;
00500       auxevent_handler (s1, (IMAuxEvent *)ev);
00501     } 
00502   }
00503 }
00504