Back to index

im-sdk  12.3.91
leif.c
Go to the documentation of this file.
00001 /*
00002 Copyright 1990-2001 Sun Microsystems, Inc. All Rights Reserved.
00003 
00004 Permission is hereby granted, free of charge, to any person obtaining a
00005 copy of this software and associated documentation files (the
00006 "Software"), to deal in the Software without restriction, including
00007 without limitation the rights to use, copy, modify, merge, publish,
00008 distribute, sublicense, and/or sell copies of the Software, and to
00009 permit persons to whom the Software is furnished to do so, subject to
00010 the following conditions: The above copyright notice and this
00011 permission notice shall be included in all copies or substantial
00012 portions of the Software.
00013 
00014 
00015 THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
00016 OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
00017 MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
00018 IN NO EVENT SHALL THE OPEN GROUP OR SUN MICROSYSTEMS, INC. BE LIABLE
00019 FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF
00020 CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH
00021 THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE EVEN IF
00022 ADVISED IN ADVANCE OF THE POSSIBILITY OF SUCH DAMAGES.
00023 
00024 
00025 Except as contained in this notice, the names of The Open Group and/or
00026 Sun Microsystems, Inc. shall not be used in advertising or otherwise to
00027 promote the sale, use or other dealings in this Software without prior
00028 written authorization from The Open Group and/or Sun Microsystems,
00029 Inc., as applicable.
00030 
00031 
00032 X Window System is a trademark of The Open Group
00033 
00034 OSF/1, OSF/Motif and Motif are registered trademarks, and OSF, the OSF
00035 logo, LBX, X Window System, and Xinerama are trademarks of the Open
00036 Group. All other trademarks and registered trademarks mentioned herein
00037 are the property of their respective owners. No right, title or
00038 interest in or to any trademark, service mark, logo or trade name of
00039 Sun Microsystems, Inc. or its licensors is granted.
00040 
00041 */
00042 
00043 /*
00044  * Author: Choe Hwanjin <krisna@kldp.org>
00045  * Modified for IIIMF Hangul language engine
00046  */
00047 
00048 #ifdef HAVE_CONFIG_H
00049 #include <config.h>
00050 #endif
00051 
00052 #include <stdio.h>
00053 #include <stdlib.h>
00054 #include <stdarg.h>
00055 #include <string.h>
00056 #include <sys/types.h>
00057 
00058 #include <X11/Xmd.h>
00059 #define CARD32BIT CARD32
00060 
00061 /*
00062  * header files for SunIM library
00063  */
00064 #include "SunIM.h"
00065 #include "SunIMMMan.h"
00066 #include "SunIMProt.h"
00067 #include "SunIMMthd.h"
00068 #include "SunIMPriv.h"
00069 #include "SunIMCore.h"
00070 #include "SunIMPub.h"
00071 
00072 #include "composer.h"
00073 
00074 /*
00075  * define If method prototype
00076  */
00077 Bool    if_hangul_OpenIF       (iml_if_t *);
00078 Bool    if_hangul_CloseIF      (iml_if_t *);
00079 Bool    if_hangul_GetIFValues  (iml_if_t *,      IMArgList, int);
00080 Bool    if_hangul_SetIFValues  (iml_if_t *,      IMArgList, int);
00081 Bool    if_hangul_OpenDesktop  (iml_desktop_t *, IMArgList, int);
00082 Bool    if_hangul_CloseDesktop (iml_desktop_t *);
00083 Bool    if_hangul_CreateSC     (iml_session_t*,  IMArgList, int);
00084 Bool    if_hangul_DestroySC    (iml_session_t *);
00085 Bool    if_hangul_GetSCValues  (iml_session_t *, IMArgList, int);
00086 Bool    if_hangul_SetSCValues  (iml_session_t *, IMArgList, int);
00087 IMText *if_hangul_ResetSC      (iml_session_t *);
00088 void    if_hangul_SetSCFocus   (iml_session_t *);
00089 void    if_hangul_UnsetSCFocus (iml_session_t *);
00090 void    if_hangul_SendEvent    (iml_session_t *, IMInputEvent * ev);
00091 
00092 /*
00093  * define if_methods_t
00094  */
00095 static if_methods_t if_methods = {
00096     if_hangul_OpenIF,
00097     if_hangul_CloseIF,
00098     if_hangul_GetIFValues,
00099     if_hangul_SetIFValues,
00100     if_hangul_OpenDesktop,
00101     if_hangul_CloseDesktop,
00102     if_hangul_CreateSC,
00103     if_hangul_DestroySC,
00104     if_hangul_GetSCValues,
00105     if_hangul_SetSCValues,
00106     if_hangul_ResetSC,
00107     if_hangul_SetSCFocus,
00108     if_hangul_UnsetSCFocus,
00109     if_hangul_SendEvent
00110 };
00111 
00112 /*
00113  * define Human Readable Name as UTFCHAR for LE
00114  */
00115 UTFCHAR lename_string[] = {
00116     0xd55c,                 /* han  */
00117     0xae00,                 /* guel */
00118     0
00119 };
00120 
00121 /*
00122  * define Human Readable Name as UTFCHAR for language
00123  */
00124 UTFCHAR ko_hrn_string[] = {
00125     0xd55c,                 /* han  */
00126     0xad6d,                 /* gueg */
00127     0xc5b4,                 /* eo   */
00128     0
00129 };
00130 
00131 static IMLEName lename = {
00132     "hangul",               /* LE id */
00133     lename_string           /* LE HRN */
00134 };
00135 
00136 static IMLocale locales[] = {
00137     { "ko",          ko_hrn_string },
00138     { NULL,          NULL          }
00139 };
00140 
00141 #ifdef WIN32
00142 #define EXPORT extern __declspec(dllexport)
00143 
00144 EXPORT
00145 
00146 #endif
00147 
00148 void
00149 if_GetIfInfo(
00150     IMArgList args,
00151     int num_args
00152 )
00153 {
00154     int i;
00155 
00156     printf("if_GetIfInfo()\n");
00157     printf("  This method is invoked when htt_server retrieves\n");
00158     printf("  if_method_t method table.\n\n");
00159 
00160     for (i = 0; i < num_args; i++, args++) {
00161         switch (args->id) {
00162             case IF_VERSION:
00163                 args->value = (IMArgVal) VERSION;
00164                 break;
00165             case IF_METHOD_TABLE:
00166                 args->value = (IMArgVal) & if_methods;
00167                 break;
00168             case IF_LE_NAME:
00169                 args->value = (IMArgVal) & lename;
00170                 break;
00171             case IF_SUPPORTED_LOCALES:
00172                 args->value = (IMArgVal) & locales;
00173                 break;
00174             case IF_SUPPORTED_OBJECTS:
00175                 break;
00176             case IF_NEED_THREAD_LOCK:
00177                 args->value = (IMArgVal) False;
00178                 break;
00179             default:
00180                 printf("\tUnknown id: %d\n", args->id);
00181                 break;
00182        }
00183     }
00184 }
00185 
00186 Bool
00187 if_hangul_OpenIF(
00188     iml_if_t * If
00189 )
00190 {
00191     printf("if_hangul_OpenIF()\n");
00192     printf("\tThis method is invoked when the Language Engine\n");
00193     printf("\tis started to use by htt_server\n\n");
00194 
00195     hangul_le_init();
00196 
00197     return True;
00198 }
00199 
00200 Bool
00201 if_hangul_CloseIF(
00202     iml_if_t * If
00203 )
00204 {
00205     printf("if_hangul_CloseIF()\n");
00206     printf("  This method is invoked when htt_server stops to\n");
00207     printf("  to use the Language Engine, which means there is\n");
00208     printf("  no client of the Language Engine is used.\n\n");
00209 
00210     return True;
00211 }
00212 
00213 Bool
00214 if_hangul_GetIFValues(
00215     iml_if_t * If,
00216     IMArgList args,
00217     int num_args
00218 )
00219 {
00220     printf("if_hangul_GetIFValues()\n");
00221     printf("  This method is invoked when the Language Engine\n");
00222     printf("  wants to set IF attributes of IM Client.\n\n");
00223     return True;
00224 }
00225 
00226 Bool
00227 if_hangul_SetIFValues(
00228     iml_if_t * If,
00229     IMArgList args,
00230     int num_args
00231 )
00232 {
00233     printf("if_hangul_SetIFValues()\n");
00234     printf("  This method is invoked when the IM client\n");
00235     printf("  wants to set IF attributes.\n\n");
00236     
00237     return True;
00238 }
00239 
00240 Bool
00241 if_hangul_OpenDesktop(
00242     iml_desktop_t * desktop,
00243     IMArgList args,
00244     int num_args
00245 )
00246 {
00247     int i;
00248 
00249     printf("if_hangul_OpenDesktop()\n");
00250     printf("  This method is invoked when the user start to use\n");
00251     printf("  the desktop, which means the first connection.\n");
00252     
00253     printf("\n");
00254     printf("  user [%s@%s] is entered\n",
00255         desktop->user_name,
00256         desktop->host_name);
00257     printf("\n");
00258 
00259     printf("  The additional info of IM client are\n");
00260 
00261     for (i = 0; i < num_args; i++, args++) {
00262         switch (args->id) {
00263             case UI_USER_NAME:
00264                 if (args->value) {
00265                     printf("       UI_USER_NAME=%s\n", args->value);
00266                 }
00267                 break;
00268             case UI_HOST_NAME:
00269                 if (args->value) {
00270                     printf("       UI_HOST_NAME=%s\n", args->value);
00271                 }
00272                 break;
00273             case UI_DISPLAY_ID:
00274                 if (args->value) {
00275                     printf("       UI_DISPLAY_ID=%s\n", args->value);
00276                 }
00277                 break;
00278             case UI_PROTOCOL_TYPE:
00279                 if (args->value) {
00280                     printf("       UI_PROTOCOL_TYPE=%s\n", args->value);
00281                 }
00282                 break;
00283             case UI_CLIENT_TYPE:
00284                 if (args->value) {
00285                     printf("       UI_CLIENT_TYPE=%s\n", args->value);
00286                 }
00287                 break;
00288             case UI_XSERVER_VENDOR:
00289                 if (args->value) {
00290                     printf("       UI_XSERVER_VENDOR=%s\n", args->value);
00291                 }
00292                 break;
00293             case UI_OS_NAME:
00294                 if (args->value) {
00295                     printf("       UI_OS_NAME=%s\n", args->value);
00296                 }
00297                 break;
00298             case UI_OS_ARCH:
00299                 if (args->value) {
00300                     printf("       UI_OS_ARCH=%s\n", args->value);
00301                 }
00302                 break;
00303             case UI_OS_VERSION:
00304                 if (args->value) {
00305                     printf("       UI_OS_VERSION=%s\n", args->value);
00306                 }
00307                 break;
00308             default:
00309                 printf("\tUnknown id=%d\n", args->id);
00310                 break;
00311             }
00312     }
00313 
00314     hangul_desktop_init(desktop);
00315     
00316     return True;
00317 }
00318 
00319 Bool
00320 if_hangul_CloseDesktop(
00321     iml_desktop_t * desktop
00322 )
00323 {
00324     Desktop *desktop_data;
00325 
00326     printf("if_hangul_CloseDesktop()\n");
00327     printf("  This method is invoked when the user exits from\n");
00328     printf("  the desktop, which means there is no IM client\n");
00329     printf("  for the user.\n");
00330     
00331     printf("\n");
00332     printf("  user [%s@%s] exited\n",
00333         desktop->user_name,
00334         desktop->host_name);
00335     printf("\n");
00336 
00337     desktop_data = (Desktop*)desktop->specific_data;
00338 
00339     free(desktop_data);
00340 
00341     return True;
00342 }
00343 
00344 Bool
00345 if_hangul_CreateSC(
00346     iml_session_t *s,
00347     IMArgList args,
00348     int num_args
00349 )
00350 {
00351     int i;
00352     iml_desktop_t *desktop = s->desktop;
00353 
00354     printf("if_hangul_CreateSC()\n");
00355     printf("  This method is invoked when a session is created\n");
00356     
00357     printf("\n");
00358     printf("  Creating a session for user [%s@%s]\n",
00359         desktop->user_name,
00360         desktop->host_name);
00361     printf("\n");
00362 
00363     printf("  The additional info of IM client are\n");
00364 
00365     for (i = 0; i < num_args; i++, args++) {
00366         switch (args->id) {
00367             case UI_USER_NAME:
00368                 if (args->value) {
00369                     printf("       UI_USER_NAME=%s\n", args->value);
00370                 }
00371                 break;
00372             case UI_HOST_NAME:
00373                 if (args->value) {
00374                     printf("       UI_HOST_NAME=%s\n", args->value);
00375                 }
00376                 break;
00377             case UI_DISPLAY_ID:
00378                 if (args->value) {
00379                     printf("       UI_DISPLAY_ID=%s\n", args->value);
00380                 }
00381                 break;
00382             case UI_PROTOCOL_TYPE:
00383                 if (args->value) {
00384                     printf("       UI_PROTOCOL_TYPE=%s\n", args->value);
00385                 }
00386                 break;
00387             case UI_CLIENT_TYPE:
00388                 if (args->value) {
00389                     printf("       UI_CLIENT_TYPE=%s\n", args->value);
00390                 }
00391                 break;
00392             case UI_XSERVER_VENDOR:
00393                 if (args->value) {
00394                     printf("       UI_XSERVER_VENDOR=%s\n", args->value);
00395                 }
00396                 break;
00397             case UI_OS_NAME:
00398                 if (args->value) {
00399                     printf("       UI_OS_NAME=%s\n", args->value);
00400                 }
00401                 break;
00402             case UI_OS_ARCH:
00403                 if (args->value) {
00404                     printf("       UI_OS_ARCH=%s\n", args->value);
00405                 }
00406                 break;
00407             case UI_OS_VERSION:
00408                 if (args->value) {
00409                     printf("       UI_OS_VERSION=%s\n", args->value);
00410                 }
00411                 break;
00412             default:
00413                 if (args->value) {
00414                     printf("       %d=%s\n", args->id, args->value);
00415                 }
00416                 break;
00417             }
00418     }
00419 
00420     hangul_session_init(s);
00421     
00422     return True;
00423 }
00424 
00425 Bool
00426 if_hangul_DestroySC(
00427     iml_session_t * s
00428 )
00429 {
00430     printf("if_hangul_DestroySC(s=0x%x)\n", (unsigned int)s);
00431     printf("  This method is invoked when the session is\n");
00432     printf("  being destroyed.\n");
00433     
00434     printf("\n");
00435     printf("  Destroying the session %x of user [%s@%s]\n",
00436         (unsigned int)s,
00437         s->desktop->user_name,
00438         s->desktop->host_name);
00439     printf("\n");
00440 
00441     hangul_session_finalize(s);
00442 
00443     return True;
00444 }
00445 
00446 Bool
00447 if_hangul_GetSCValues(
00448     iml_session_t * s,
00449     IMArgList args,
00450     int num_args
00451 )
00452 {
00453     int i;
00454     IMArg *p = args;
00455 
00456     printf("if_hangul_GetSCValues(s=0x%x)\n", (unsigned int)s);
00457     printf("  This method is invoked when the Language Engine\n");
00458     printf("  wants to set SC attributes of IM Client.\n\n");
00459     
00460     for (i = 0; i < num_args; i++, p++) {
00461         switch (p->id) {
00462             default:
00463                 printf("args: %d: %p\n", p->id, p->value);
00464                 break;
00465             }
00466     }
00467     return True;
00468 }
00469 
00470 Bool
00471 if_hangul_SetSCValues(
00472     iml_session_t * s,
00473     IMArgList args,
00474     int num_args
00475 )
00476 {
00477     int i;
00478     IMArg *p = args;
00479     
00480     printf("if_hangul_SetSCValues(s=0x%x)\n", (unsigned int)s);
00481     printf("  This method is invoked when the IM client\n");
00482     printf("  wants to set SC attributes.\n\n");
00483     
00484     hangul_prep(s);
00485     for (i = 0; i < num_args; i++, p++) {
00486         switch (p->id) {
00487         case SC_TRIGGER_ON_NOTIFY:
00488             printf(" SC_TRIGGER_ON_NOTIFY: received\n");
00489             hangul_conversion_on(s);
00490 
00491             break;
00492         case SC_TRIGGER_OFF_NOTIFY:
00493             printf(" SC_TRIGGER_OFF_NOTIFY: received\n");
00494             hangul_conversion_off(s);
00495 
00496             break;
00497         case SC_REALIZE:
00498             if(s->desktop->session_count == 1){
00499                     printf("       SC_REALIZE: just after OpenDesktop\n");
00500             } else {
00501                     printf("       SC_REALIZE: received\n");
00502             }
00503             break;
00504         default:
00505             printf("\tUnknown id=%d\n", args->id);
00506             break;
00507         }
00508     }
00509     printf("\n");
00510 
00511     hangul_exec(s);
00512     return True;
00513 }
00514 
00515 IMText *
00516 if_hangul_ResetSC(
00517     iml_session_t * s
00518 )
00519 {
00520     IMText *text;
00521     printf("if_hangul_ResetSC(s=0x%x)\n", (unsigned int)s);
00522     printf("  This method is invoked when the IM client\n");
00523     printf("  wants to reset the IC.\n\n");
00524 
00525     hangul_prep(s);
00526     text = hangul_session_reset(s);
00527     hangul_exec(s);
00528     
00529     return text;
00530 }
00531 
00532 void
00533 if_hangul_SetSCFocus(
00534     iml_session_t * s
00535 )
00536 {
00537     printf("if_hangul_SetSCFocus(s=0x%x)\n", (unsigned int)s);
00538     printf("  This method is invoked when the IM client\n");
00539     printf("  gets the input focus.\n\n");
00540 
00541     hangul_prep(s);
00542     hangul_focus(s);
00543     hangul_exec(s);
00544 }
00545 
00546 void
00547 if_hangul_UnsetSCFocus(
00548     iml_session_t * s
00549 )
00550 {
00551     printf("if_hangul_UnsetSCFocus(s=0x%x)\n", (unsigned int)s);
00552     printf("  This method is invoked when the IM client\n");
00553     printf("  loses the input focus.\n\n");
00554 
00555     hangul_prep(s);
00556     hangul_unfocus(s);
00557     hangul_exec(s);
00558 }
00559 
00560 void
00561 if_hangul_SendEvent(
00562     iml_session_t * s,
00563     IMInputEvent * ev
00564 )
00565 {
00566     hangul_prep(s);
00567     if (ev->type == IM_EventKeyList) {
00568         IMKeyListEvent *keylistevent = (IMKeyListEvent *) ev;
00569         IMKeyEventStruct *key = (IMKeyEventStruct *) keylistevent->keylist;
00570 
00571         printf("Event: [%c](0x%x)\n", key->keyChar, key->keyCode);
00572         if (!hangul_composer(s, key))
00573             hangul_foward_keyevent(s, key);
00574     } else {
00575         printf("Event: %d\n", ev->type);
00576     }
00577     hangul_exec(s);
00578 }
00579 
00580 /* vim: set sw=4 ts=8 et : */