Back to index

im-sdk  12.3.91
freewnn.c
Go to the documentation of this file.
00001 /*
00002 Copyright (C) 1990-2001 Sun Microsystems, Inc.
00003 Copyright (C) 2001,2004 Red Hat, Inc.
00004 Copyright (C) 2001,2004 Yukihiro Nakai <nakai@gnome.gr.jp>
00005 
00006 Permission is hereby granted, free of charge, to any person obtaining a
00007 copy of this software and associated documentation files (the
00008 "Software"), to deal in the Software without restriction, including
00009 without limitation the rights to use, copy, modify, merge, publish,
00010 distribute, sublicense, and/or sell copies of the Software, and to
00011 permit persons to whom the Software is furnished to do so, subject to
00012 the following conditions: The above copyright notice and this
00013 permission notice shall be included in all copies or substantial
00014 portions of the Software.
00015 
00016 
00017 THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
00018 OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
00019 MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
00020 IN NO EVENT SHALL THE OPEN GROUP OR SUN MICROSYSTEMS, INC. BE LIABLE
00021 FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF
00022 CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH
00023 THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE EVEN IF
00024 ADVISED IN ADVANCE OF THE POSSIBILITY OF SUCH DAMAGES.
00025 
00026 
00027 Except as contained in this notice, the names of The Open Group and/or
00028 Red Hat, Inc. shall not be used in advertising or otherwise to
00029 promote the sale, use or other dealings in this Software without prior
00030 written authorization from The Open Group and/or Red Hat, Inc.,
00031 as applicable.
00032 
00033 
00034 X Window System is a trademark of The Open Group
00035 
00036 OSF/1, OSF/Motif and Motif are registered trademarks, and OSF, the OSF
00037 logo, LBX, X Window System, and Xinerama are trademarks of the Open
00038 Group. All other trademarks and registered trademarks mentioned herein
00039 are the property of their respective owners. No right, title or
00040 interest in or to any trademark, service mark, logo or trade name of
00041 Red Hat, Inc. or its licensors is granted.
00042 
00043 */
00044 
00045 #include <stdio.h>
00046 #include <stdlib.h>
00047 #include <unistd.h>
00048 #include <string.h>
00049 #include <pwd.h>
00050 #include <sys/types.h>
00051 
00052 #include "SunIM.h"
00053 
00054 #include <dlfcn.h>
00055 #include <jllib.h>
00056 #include "csconv.h"
00057 
00058 #ifndef BUFSIZE
00059 #define BUFSIZE 1024
00060 #endif
00061 
00062 #define WNNRCFILE "/etc/FreeWnn/ja/wnnenvrc"
00063 
00064 #define CSC_OPEN_LOCALE "csconv_open_locale"
00065 #define CSC_OPEN        "csconv_open"
00066 #define CSC_CONV        "csconv"
00067 #define CSC_CLOSE       "csconv_close"
00068 
00069 #define wnn_printf(a)       printf a
00070 
00071 typedef csconv_t        (* csc_open_locale_t)(const char *,
00072                                               const char *, const char *);
00073 typedef csconv_t        (* csc_open_t)(const char *, const char *);
00074 typedef size_t          (* csc_conv_t)(csconv_t, const char **, size_t *,
00075                                        char **, size_t *);
00076 typedef int             (* csc_close_t)(csconv_t);
00077 
00078 static void *                   csc_handle = NULL;
00079 static csc_open_locale_t        csc_open_locale;
00080 static csc_open_t               csc_open;
00081 static csc_conv_t               csc_conv;
00082 static csc_close_t              csc_close;
00083 static csconv_t                 csconv_cd = NULL;
00084 static csconv_t                 csconv_utf8_cd = NULL;
00085 
00086 Bool if_freewnn_OpenIF(iml_if_t *);
00087 Bool if_freewnn_CloseIF(iml_if_t *);
00088 Bool if_freewnn_GetIFValues(iml_if_t *, IMArgList, int);
00089 Bool if_freewnn_SetIFValues(iml_if_t *, IMArgList, int);
00090 Bool if_freewnn_OpenDesktop(iml_desktop_t *, IMArgList, int);
00091 Bool if_freewnn_CloseDesktop(iml_desktop_t *);
00092 Bool if_freewnn_CreateSC(iml_session_t*, IMArgList, int);
00093 Bool if_freewnn_DestroySC(iml_session_t *);
00094 Bool if_freewnn_GetSCValues(iml_session_t *, IMArgList, int);
00095 Bool if_freewnn_SetSCValues(iml_session_t *, IMArgList, int);
00096 IMText *if_freewnn_ResetSC(iml_session_t *);
00097 void if_freewnn_SetSCFocus(iml_session_t *);
00098 void if_freewnn_UnsetSCFocus(iml_session_t *);
00099 void if_freewnn_SendEvent(iml_session_t *, IMInputEvent * ev);
00100 
00101 void freewnn_status_draw(iml_session_t *s, char* str);
00102 
00103 static if_methods_t if_methods = {
00104   if_freewnn_OpenIF,
00105   if_freewnn_CloseIF,
00106   if_freewnn_GetIFValues,
00107   if_freewnn_SetIFValues,
00108   if_freewnn_OpenDesktop,
00109   if_freewnn_CloseDesktop,
00110   if_freewnn_CreateSC,
00111   if_freewnn_DestroySC,
00112   if_freewnn_GetSCValues,
00113   if_freewnn_SetSCValues,
00114   if_freewnn_ResetSC,
00115   if_freewnn_SetSCFocus,
00116   if_freewnn_UnsetSCFocus,
00117   if_freewnn_SendEvent
00118 };
00119 
00120 UTFCHAR lename_string[] = {
00121   0x3046, 0x3093, 0x306C, 0x4C, 0x45, 0x0 /* Wnn LE */
00122 };
00123 
00124 UTFCHAR jahrn_string[] = {
00125   0x65E5, 0x672C, 0x8A9E /* Nihongo */
00126 };
00127 
00128 static IMLEName lename = {
00129     "FreeWnnLE",
00130     lename_string
00131 };
00132 
00133 static IMLocale locales[] = {
00134     {
00135         "ja",
00136         jahrn_string
00137     },
00138     {NULL, NULL},
00139 };
00140 
00141 #include "convtable.h"
00142 
00143 typedef struct {
00144   Bool conv_on; /* conversion mode is on */
00145   char* preedit_buf; /* preedit buffer */
00146   Bool preedit_start; /* preedit window draw started */
00147   struct wnn_buf* wbuf; /* Wnn Buffer */
00148   Bool kanji_on; /* Under selecting candidate */
00149 } FreeWnnSession;
00150 
00151 FreeWnnSession*
00152 freewnn_session_data(iml_session_t *s) {
00153   return (FreeWnnSession*)s->specific_data;
00154 }
00155 
00156 
00157 w_char*
00158 char2wchar(unsigned char* str) {
00159   w_char* result = NULL;
00160   int i=0;
00161   int j=0;
00162   int count = 0;
00163 
00164   if( str == NULL ) return NULL;
00165   if( *str == '\0' ) return NULL;
00166 
00167   for(i=0;i<strlen(str);i++) {
00168     count++;
00169     if( str[i] & 0x80 )
00170       i++;
00171   }
00172 
00173   result = (w_char*)calloc(count+1, sizeof(w_char));
00174   for(i=0;i<strlen(str);i++) {
00175     if( str[i] & 0x80 ) {
00176       result[j] =  str[i];
00177       result[j] = (result[j] << 8 ) | str[++i];
00178     } else {
00179       result[j] = str[i];
00180     }
00181     j++;
00182   }
00183 
00184 #if 0
00185   {
00186     for(i=0;i<count;i++) {
00187       printf("0x%04x\n", result[i]);
00188     }
00189   }
00190 #endif
00191 
00192   return result;
00193 }
00194 
00195 unsigned char*
00196 wchar2char(w_char* wstr) {
00197   char* result = NULL;
00198   int i;
00199   int j;
00200   int count = 0;
00201 
00202   if( wstr == NULL ) return NULL;
00203 
00204   if( *wstr == 0 ) return NULL;
00205 
00206   for(i=0;wstr[i] != 0;i++) 
00207     count++;
00208 
00209   result = (unsigned char*)calloc(count*2+1, sizeof(unsigned char));
00210   j=0;
00211   for(i=0;i<count;i++) {
00212     if( wstr[i] & 0xff00 ) {
00213       result[j++] = wstr[i] >> 8;
00214     }
00215     result[j++] = wstr[i] & 0xff;
00216   }
00217 
00218   return result;
00219 }
00220 
00221 void
00222 freewnn_conversion(iml_session_t *s) {
00223   FreeWnnSession* session_data = freewnn_session_data(s);
00224   w_char* wcbuf = NULL;
00225   w_char kanjibuf[BUFSIZE];
00226 
00227   bzero(kanjibuf, sizeof(w_char)*BUFSIZE);
00228 
00229   if( strlen(session_data->preedit_buf) == 0 )
00230     return;
00231 
00232   if( session_data->kanji_on == False ) {
00233     wcbuf = char2wchar(session_data->preedit_buf);
00234     jl_ren_conv(session_data->wbuf, wcbuf, 0, -1, WNN_NO_USE);
00235     jl_zenkouho(session_data->wbuf, 0, WNN_NO_USE, WNN_UNIQ);
00236     session_data->kanji_on = True;
00237   }
00238 
00239   jl_get_kanji(session_data->wbuf, 0, -1, kanjibuf);
00240   bzero(session_data->preedit_buf, sizeof(char)*BUFSIZE);
00241   wnn_printf(("%s\n", wchar2char(kanjibuf)));
00242   strcpy(session_data->preedit_buf, wchar2char(kanjibuf));
00243   jl_next(session_data->wbuf);
00244 }
00245 
00246 
00247 void printError(char* s) {
00248   wnn_printf(("%s\n", s));
00249 }
00250 
00251 int printConfirm(char* s) {
00252   wnn_printf(("%s\n", s));
00253   return 1;
00254 }
00255 
00256 int
00257 strrncmp(char* s1, char* s2, size_t n) {
00258   char* s1tmp = s1;
00259   if( strlen(s1) >= n ) {
00260     s1tmp += strlen(s1)-n;
00261   }
00262 
00263   return strcmp(s1tmp, s2);
00264 }
00265 
00266 char*
00267 roma2kana(char* romastr) {
00268   char* result = NULL;
00269   int tsize = sizeof(kanatable)/sizeof(kanatable[0]);
00270   int i;
00271 
00272   if( romastr == NULL ) return NULL;
00273   if( *romastr == '\0' ) return NULL;
00274 
00275   for(i=0;i<tsize;i++) {
00276     romapair rp = kanatable[i];
00277     if( strrncmp(romastr, rp.roma, strlen(rp.roma)) == 0 ) {
00278       int len = strlen(romastr)-strlen(rp.roma)+strlen(rp.kana)+1;
00279       result = (char*)calloc(len+1, sizeof(char));
00280       strncat(result, romastr, strlen(romastr)-strlen(rp.roma));
00281       strcat(result, rp.kana);
00282       return result;
00283     }
00284   }
00285 
00286   result = strdup(romastr); /* No change */
00287 
00288   return result;
00289 }
00290 
00291 void
00292 buffer_tailcut(char* buf) {
00293   if( buf == NULL ) return;
00294   if( *buf == '\0') return;
00295 
00296   if( strlen(buf) == 1 ) {
00297     buf[strlen(buf)-1] = '\0';
00298   } else if( buf[strlen(buf)-1] & 0x80 ) {
00299     buf[strlen(buf)-1] = '\0';
00300     buf[strlen(buf)-1] = '\0';
00301   } else
00302     buf[strlen(buf)-1] = '\0';
00303 }
00304 
00305 void
00306 buffer_append(char* buf, char ch) {
00307   char* kana = NULL;
00308 
00309   if( buf == NULL ) return;
00310 
00311   buf[strlen(buf)] = ch;
00312   buf[strlen(buf)] = '\0';
00313 
00314   kana = roma2kana(buf);
00315   strcpy(buf, kana);
00316 
00317   //free(kana);
00318 }
00319 
00320 void
00321 freewnn_conversion_on(iml_session_t *s) {
00322   FreeWnnSession* session_data = freewnn_session_data(s);
00323 
00324   session_data->conv_on = True;
00325   wnn_printf(("Conversion on\n"));
00326 }
00327 
00328 void
00329 freewnn_conversion_off(iml_session_t *s) {
00330   FreeWnnSession* session_data = freewnn_session_data(s);
00331 
00332   session_data->conv_on = False;
00333   wnn_printf(("Conversion off\n"));
00334 }
00335 
00336 IMFeedbackList *
00337 create_feedback(iml_session_t *s, int size)
00338 {
00339     int i;
00340     IMFeedbackList *feedback, *fbl;
00341     IMFeedback *fb;
00342 
00343     if (!s) return NULL;
00344 
00345     feedback = ((IMFeedbackList *)
00346                 s->If->m->iml_new(s, sizeof(IMFeedbackList) * size));
00347     for (i = 0; i < size; i++) {
00348         fbl = &feedback[i];
00349         fbl->count_feedbacks = 1;
00350         fb = ((IMFeedback *) s->If->m->iml_new(s, sizeof(IMFeedback) * 4));
00351         fbl->feedbacks = fb;
00352         memset(fbl->feedbacks, 0, sizeof(IMFeedback) * 4);
00353     }
00354     return feedback;
00355 }
00356 
00357 IMText*
00358 create_IMText(iml_session_t *s, int len)
00359 {
00360     IMText *p;
00361 
00362     if (!s) return NULL;
00363 
00364     p = (IMText *) s->If->m->iml_new(s, sizeof(IMText));
00365     memset(p, 0, sizeof(IMText));
00366     p->encoding = UTF16_CODESET;
00367     p->text.utf_chars = ((UTFCHAR *)
00368                          s->If->m->iml_new(s, sizeof(UTFCHAR) * (len + 1)));
00369     p->char_length = len;
00370     p->feedback = create_feedback(s, len);
00371 
00372     return p;
00373 }
00374 
00375 int
00376 ustrlen(UTFCHAR* ustr) {
00377   int i;
00378 
00379   if( ustr == NULL ) return 0;
00380   if( ustr[0] == 0x0000 ) return 0;
00381 
00382   for(i=0; ; i++) {
00383     if (ustr[i] == 0x0000)
00384       return i;
00385   }
00386 
00387 }
00388 
00389 UTFCHAR*
00390 UTF8_to_UTFCHAR(unsigned char* str) {
00391   UTFCHAR *p, *ustr = NULL;
00392   int len, ulen;
00393 
00394   const char *csc_arg_str_ccp; /* For compiler optimization */
00395   char *csc_arg_str_cp; /* For compiler optimization */
00396 
00397   if( str == NULL ) return NULL;
00398   if( *str == '\0' ) return NULL;
00399 
00400   if( csconv_utf8_cd == NULL ) {
00401     csconv_utf8_cd = csc_open("UTF-16", "UTF-8");
00402     if( csconv_utf8_cd == NULL ) {
00403       wnn_printf(("csconv_open failed.\n"));
00404       return NULL;
00405     }
00406   }
00407 
00408   len = strlen(str);
00409 
00410   ulen = sizeof(UTFCHAR)*(len+1);
00411   p = ustr = (UTFCHAR*)calloc(len+1, sizeof(UTFCHAR));
00412 
00413   /* Below 2 lines are to prevent gcc's warning and for the sake
00414      of compiler optimization */
00415   csc_arg_str_ccp = (const char*)str;
00416   csc_arg_str_cp = (char*)ustr;
00417 
00418   csc_conv(csconv_utf8_cd, &csc_arg_str_ccp, &len, &csc_arg_str_cp, &ulen);
00419 
00420   *ustr = 0;
00421 
00422   return p;
00423 }
00424 
00425 UTFCHAR*
00426 euc2UTFCHAR(unsigned char* str) {
00427   UTFCHAR *p, *ustr = NULL;
00428   int len, ulen;
00429 
00430   const char *csc_arg_str_ccp; /* For compiler optimization */
00431   char *csc_arg_str_cp; /* For compiler optimization */
00432 
00433   if( str == NULL ) return NULL;
00434   if( *str == '\0' ) return NULL;
00435 
00436   if( csconv_cd == NULL ) {
00437     csconv_cd = csc_open_locale("ja_JP.eucJP", "UTF-16", "MultiByte");
00438     if( csconv_cd == NULL ) {
00439       wnn_printf(("csconv_open failed.\n"));
00440       return NULL;
00441     }
00442   }
00443 
00444   len = strlen(str);
00445 
00446   ulen = sizeof(UTFCHAR)*(len+1);
00447   p = ustr = (UTFCHAR*)calloc(len+1, sizeof(UTFCHAR));
00448 
00449   /* Below 2 lines are to prevent gcc's warning and for the sake
00450      of compiler optimization */
00451   csc_arg_str_ccp = (const char*)str;
00452   csc_arg_str_cp = (char*)ustr;
00453 
00454   csc_conv(csconv_cd, &csc_arg_str_ccp, &len, &csc_arg_str_cp, &ulen);
00455 
00456   *ustr = 0;
00457 
00458   return p;
00459 }
00460 
00461 IMText*
00462 freewnn_UTF8_to_IMText(iml_session_t *s, char* str) {
00463   IMText* p = NULL;
00464   UTFCHAR *ustr = NULL;
00465 
00466   ustr = UTF8_to_UTFCHAR(str);
00467 
00468   p = create_IMText(s, ustrlen(ustr));
00469   memcpy(p->text.utf_chars, ustr, (ustrlen(ustr)+1)*sizeof(UTFCHAR));
00470 
00471   return p;
00472 }
00473 
00474 IMText*
00475 freewnn_string2IMText(iml_session_t *s, char* str) {
00476   IMText* p = NULL;
00477   UTFCHAR *ustr = NULL;
00478 
00479   ustr = euc2UTFCHAR(str);
00480 
00481   p = create_IMText(s, ustrlen(ustr));
00482   memcpy(p->text.utf_chars, ustr, (ustrlen(ustr)+1)*sizeof(UTFCHAR));
00483 
00484   return p;
00485 }
00486 
00487 void
00488 commit_string(iml_session_t *s) {
00489   iml_inst *lp = NULL;
00490   iml_inst *rrv = NULL;
00491   IMText* p = NULL;
00492   FreeWnnSession* session_data = freewnn_session_data(s);
00493   char buf[BUFSIZE*2];
00494 
00495   bzero(buf, BUFSIZE*2);
00496   if( strlen(session_data->preedit_buf) > 0 )
00497     strcpy(buf, session_data->preedit_buf);
00498 
00499   session_data->kanji_on = False;
00500 
00501   if( strlen(buf) == 0 )
00502     return;
00503 
00504   bzero(session_data->preedit_buf, sizeof(char)*BUFSIZE);
00505 
00506   p = freewnn_string2IMText(s, buf);
00507   lp = s->If->m->iml_make_commit_inst(s, p);
00508   s->If->m->iml_link_inst_tail(&rrv, lp);
00509   s->If->m->iml_execute(s, &rrv);
00510 }
00511 
00512 void
00513 preedit_done(iml_session_t *s) {
00514   FreeWnnSession* session_data = freewnn_session_data(s);
00515 
00516   if( session_data->preedit_start == True ) {
00517     iml_inst *lp;
00518     lp = s->If->m->iml_make_preedit_done_inst(s);
00519     s->If->m->iml_execute(s, &lp);
00520     session_data->preedit_start = False;
00521   }
00522 }
00523 
00524 void
00525 preedit_draw(iml_session_t *s) {
00526   iml_inst *lp = NULL;
00527   iml_inst *rrv = NULL;
00528   UTFCHAR *ustr = NULL;
00529   int i;
00530   IMText *p = NULL;
00531   FreeWnnSession* session_data = freewnn_session_data(s);
00532   IMFeedbackList *fbl;
00533   IMFeedback *fb;
00534 
00535   if( session_data->preedit_start == False) {
00536     lp = s->If->m->iml_make_preedit_start_inst(s);
00537     s->If->m->iml_link_inst_tail(&rrv, lp);
00538     session_data->preedit_start = True;
00539   }
00540 
00541   ustr = euc2UTFCHAR(session_data->preedit_buf);
00542 
00543   if( ustrlen(ustr) == 0 ) {
00544     free(ustr);
00545     return;
00546   }
00547 
00548   p = create_IMText(s, ustrlen(ustr));
00549   memcpy(p->text.utf_chars, ustr, (ustrlen(ustr)+1)*sizeof(UTFCHAR));
00550   for(i=0;i<ustrlen(ustr);i++) {
00551     fbl = &p->feedback[i];
00552     fb = &fbl->feedbacks[0];
00553     IM_FEEDBACK_TYPE(fb) = IM_DECORATION_FEEDBACK;
00554     IM_FEEDBACK_VALUE(fb) = IMUnderline;
00555     IM_FEEDBACK_COUNT(fbl) = 1;
00556   }
00557 
00558   lp = s->If->m->iml_make_preedit_draw_inst(s, p);
00559   s->If->m->iml_link_inst_tail(&rrv, lp);
00560   s->If->m->iml_execute(s, &rrv);
00561 }
00562 
00563 static void
00564 dlopen_csconv()
00565 {
00566       csc_handle = dlopen(CSC_PATH, RTLD_LAZY);
00567       if (NULL == csc_handle) {
00568         csc_handle = (void *)(-1);
00569         return;
00570       }
00571 
00572       csc_open_locale = (csc_open_locale_t)dlsym(csc_handle, CSC_OPEN_LOCALE);
00573       csc_open = (csc_open_t)dlsym(csc_handle, CSC_OPEN);
00574       csc_conv = (csc_conv_t)dlsym(csc_handle, CSC_CONV);
00575       csc_close = (csc_close_t)dlsym(csc_handle, CSC_CLOSE);
00576 
00577       if ((NULL == csc_open) ||
00578           (NULL == csc_conv) || (NULL == csc_close)) {
00579         dlclose(csc_handle);
00580         csc_handle = (void *)(-1);
00581         return;
00582       }
00583 }
00584 
00585 void
00586 freewnn_process_keyevent(iml_session_t *s, IMKeyListEvent* kev) {
00587   FreeWnnSession* session_data = freewnn_session_data(s);
00588 
00589   IMKeyEventStruct *k = (IMKeyEventStruct*)kev->keylist;
00590 
00591   if( k->keyCode == IM_VK_SPACE && (k->modifier & IM_CTRL_MASK) ) {
00592     if( session_data->conv_on == True ) {
00593       freewnn_conversion_off(s);
00594     } else {
00595       freewnn_conversion_on(s);
00596     }
00597     return;
00598   }
00599 
00600   if( session_data->conv_on == True ) {
00601     if( k->keyCode == IM_VK_ENTER ) {
00602       commit_string(s);
00603       preedit_done(s);
00604       return;
00605     }
00606     if( k->keyCode == IM_VK_SPACE ) {
00607       freewnn_conversion(s);
00608       preedit_draw(s);
00609       return;
00610     }
00611     if( k->keyCode >= 65 && k->keyCode <= 90 ) {
00612       buffer_append(session_data->preedit_buf, k->keyCode - 65 + 'a');
00613       preedit_draw(s);
00614     }
00615   } else {
00616     iml_inst* lp;
00617     lp = s->If->m->iml_make_keypress_inst(s, ((IMKeyEventStruct*)kev->keylist));
00618     s->If->m->iml_execute(s, &lp);
00619   }
00620 }
00621 
00622 void
00623 if_GetIfInfo(IMArgList args, int num_args) {
00624   int i;
00625   wnn_printf(("if_GetIfInfo()\n"));
00626   
00627   for (i = 0; i < num_args; i++, args++) {
00628     switch (args->id) {
00629     case IF_VERSION:
00630       args->value = (IMArgVal) "1.2";
00631       break;
00632     case IF_METHOD_TABLE:
00633       args->value = (IMArgVal) & if_methods;
00634       break;
00635     case IF_LE_NAME:
00636       args->value = (IMArgVal) & lename;
00637       break;
00638     case IF_SUPPORTED_LOCALES:
00639       args->value = (IMArgVal) & locales;
00640       break;
00641     case IF_SUPPORTED_OBJECTS:
00642       break;
00643     case IF_NEED_THREAD_LOCK:
00644       args->value = (IMArgVal) False;
00645       break;
00646     default:
00647       break;
00648     }
00649   }
00650 }
00651 
00652 Bool
00653 if_freewnn_OpenIF(iml_if_t * If) {
00654 
00655   if( csc_handle == NULL )
00656     dlopen_csconv();
00657 
00658     wnn_printf(("if_freewnn_OpenIF()\n"));
00659     return True;
00660 }
00661 
00662 Bool
00663 if_freewnn_CloseIF(iml_if_t * If)
00664 {
00665     wnn_printf(("if_freewnn_CloseIF()\n"));
00666     return True;
00667 }
00668 
00669 
00670 
00671 Bool
00672 if_freewnn_GetIFValues(iml_if_t * If, IMArgList args, int num_args) {
00673     wnn_printf(("if_freewnn_GetIFValues()\n"));
00674     return True;
00675 }
00676 
00677 Bool
00678 if_freewnn_SetIFValues(iml_if_t * If, IMArgList args, int num_args) {
00679     wnn_printf(("if_freewnn_SetIFValues()\n"));
00680     
00681     return True;
00682 }
00683 
00684 Bool
00685 if_freewnn_OpenDesktop(iml_desktop_t * desktop, IMArgList args, int num_args) {
00686     wnn_printf(("if_freewnn_OpenDesktop()\n"));
00687     
00688     return True;
00689 }
00690 
00691 Bool
00692 if_freewnn_CloseDesktop(iml_desktop_t * desktop) {
00693     wnn_printf(("if_freewnn_CloseDesktop()\n"));
00694     return True;
00695 }
00696 
00697 Bool
00698 if_freewnn_CreateSC(iml_session_t *s, IMArgList args, int num_args) {
00699 
00700   struct passwd *p = NULL;
00701   struct wnn_env* wenv = NULL;
00702   char* envname = "openi18n";
00703   FreeWnnSession* session_data
00704     = (FreeWnnSession*)calloc(sizeof(FreeWnnSession), 1);
00705 
00706   session_data->kanji_on = False;
00707   session_data->conv_on = False;
00708   session_data->preedit_start = False;
00709   session_data->preedit_buf = (char*)calloc(sizeof(char), BUFSIZE);
00710   p = getpwuid(getuid());
00711   if( p )
00712     envname = p->pw_name;
00713   session_data->wbuf = jl_open_lang(envname, getenv("JSERVER"), "ja_JP", NULL,
00714     printError, printConfirm, 0);
00715 
00716   if( session_data->wbuf == NULL ) {
00717     wnn_printf(("jl_open_lang() failed.\n"));
00718     return False;
00719   }
00720 
00721   wenv = jl_env_get(session_data->wbuf);
00722   if( wenv == NULL ) {
00723     wnn_printf(("jl_env_get() failed.\n"));
00724     return False;
00725   }
00726 
00727   jl_set_env_wnnrc(wenv, WNNRCFILE, printConfirm, printError);
00728 
00729   s->specific_data = (void*)session_data;
00730     
00731   return True;
00732 }
00733 
00734 Bool
00735 if_freewnn_DestroySC(iml_session_t * s) {
00736     wnn_printf(("if_freewnn_DestroySC()\n"));
00737     
00738     return True;
00739 }
00740 
00741 Bool
00742 if_freewnn_GetSCValues(iml_session_t * s, IMArgList args, int num_args) {
00743     wnn_printf(("if_freewnn_GetSCValues()\n"));
00744 
00745     return True;
00746 }
00747 
00748 Bool
00749 if_freewnn_SetSCValues( iml_session_t * s, IMArgList args, int num_args) {
00750     int i;
00751     IMArg *p = args;
00752     
00753     wnn_printf(("if_freewnn_SetSCValues()\n"));
00754     
00755     for (i = 0; i < num_args; i++, p++) {
00756         switch (p->id) {
00757             case SC_TRIGGER_ON_NOTIFY:
00758                 wnn_printf(("      SC_TRIGGER_ON_NOTIFY: received\n"));
00759                 freewnn_conversion_on(s);
00760                 freewnn_status_draw(s, "  [あ]\n FreeWnn ");
00761                 break;
00762             case SC_TRIGGER_OFF_NOTIFY:
00763                 wnn_printf(("      SC_TRIGGER_OFF_NOTIFY: received\n"));
00764                 freewnn_conversion_off(s);
00765                 freewnn_status_draw(s, "   [A]\n FreeWnn ");
00766                 break;
00767             case SC_REALIZE:
00768                 break;
00769             default:
00770                 break;
00771             }
00772     }
00773     return True;
00774 }
00775 
00776 IMText *
00777 if_freewnn_ResetSC(iml_session_t * s) {
00778     wnn_printf(("if_freewnn_ResetSC()\n"));
00779     
00780     return (IMText *) NULL;
00781 }
00782 
00783 void
00784 if_freewnn_SetSCFocus(iml_session_t * s) {
00785     wnn_printf(("if_freewnn_SetSCFocus()\n"));
00786 }
00787 
00788 void
00789 if_freewnn_UnsetSCFocus(iml_session_t * s) {
00790     wnn_printf(("if_freewnn_UnsetSCFocus()\n"));
00791 }
00792 
00793 void
00794 if_freewnn_SendEvent(iml_session_t * s, IMInputEvent * ev) {
00795   wnn_printf(("if_freewnn_SendEvent()\n"));
00796     
00797   if (ev->type == IM_EventKeyList) {
00798     freewnn_process_keyevent(s, (IMKeyListEvent*)ev);
00799   }
00800 }
00801 
00802 void
00803 freewnn_status_draw(iml_session_t *s, char* str)
00804 {
00805   IMText *p = NULL;
00806   iml_inst *lp = NULL;
00807   iml_inst *rrv = NULL;
00808   p = freewnn_UTF8_to_IMText(s, str);
00809   lp = s->If->m->iml_make_status_draw_inst(s, p);
00810   s->If->m->iml_link_inst_tail(&rrv, lp);
00811   s->If->m->iml_execute(s, &rrv);
00812 }