Back to index

im-sdk  12.3.91
unit_input.h
Go to the documentation of this file.
00001 /*
00002   Copyright 2002-2003 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 #ifndef _UNITINPUT_H_
00043 #define _UNITINPUT_H_
00044 
00045 #include "config.h"
00046 #include <string.h>
00047 #include <stdlib.h>
00048 #include <libxml/xmlmemory.h>
00049 #include <libxml/parser.h>
00050 #include <dirent.h>     /* for #define NAME_MAX 255  */
00051 #include <fcntl.h>      /* for mode_t */
00052 #include <sys/param.h>  /* for #define PATH_MAX 4096 */
00053 #include <X11/Xmd.h>
00054 #include "SunIM.h"
00055 #include "logf.h"
00056 
00057 #ifndef NAME_MAX
00058 #define NAME_MAX 255
00059 #endif
00060     /***************************************************************************/
00061     /*                          Key  Definition                                */
00062     /***************************************************************************/
00063 
00064     /* Key Used by Input Method Manager */
00065 #define IMM_NOT_USED_KEY           0
00066 #define IMM_USED_KEY               1
00067 #define ENGLISH_NONENGLISH_SWITCH_KEY 4
00068 #define ROUND_SWITCH_KEY           5  
00069 
00070 #define SWITCH_F1_KEY                     6
00071 #define SWITCH_F2_KEY                     (SWITCH_F1_KEY+1)
00072 #define SWITCH_F3_KEY                     (SWITCH_F1_KEY+2)
00073 #define SWITCH_F4_KEY                     (SWITCH_F1_KEY+3)
00074 #define SWITCH_F5_KEY                     (SWITCH_F1_KEY+4)
00075 #define SWITCH_F6_KEY                     (SWITCH_F1_KEY+5)
00076 #define SWITCH_F7_KEY                     (SWITCH_F1_KEY+6)
00077 #define SWITCH_F8_KEY                     (SWITCH_F1_KEY+7)
00078 #define SWITCH_F9_KEY                     (SWITCH_F1_KEY+8)
00079 #define SWITCH_F10_KEY                    (SWITCH_F1_KEY+9)
00080 #define SWITCH_F11_KEY                    (SWITCH_F1_KEY+10)
00081 #define SWITCH_F12_KEY                    (SWITCH_F1_KEY+11)
00082 
00083     /* Key Used by Input Method Entry */
00084 #define IME_NOT_USED_KEY           0
00085 #define IME_USED_KEY               1
00086 #define ESC_KEY                           2
00087 #define BACKSPACE_KEY                     3
00088 #define RETURN_KEY                        4
00089 #define INSERT_KEY                 5
00090 #define DELETE_KEY                 6
00091 #define HOME_KEY                   7
00092 #define END_KEY                           8
00093 #define PAGEUP_KEY                        9
00094 #define PAGEDOWN_KEY                      10
00095 #define TAB_KEY                    11
00096 #define IME_DEADKEY_AS_HOTKEY      12
00097 #define IME_COMPOSE_KEY_AS_HOTKEY  13
00098 #define IME_EURO_KEY_AS_HOTKEY            14
00099 #define SPACE_KEY                         0x20
00100 #define IME_QUOTE                         0x27
00101 #define IME_BACK_QUOTE             0x60
00102 #define IME_ASCIICIRCUM            0x5e
00103 #define IME_GREATER                0x3e
00104 #define IME_QUOTEDBL               0x22
00105 #define IME_ASCIITILDE                    0x7e
00106 
00107     /***************************************************************************/
00108     /*                    Input Method Engine  Definition                      */
00109     /***************************************************************************/
00110 #define       MAX_CANDIDATES_NUM          16
00111 #define MAX_INPUT_KEY_NUM          256
00112 #define MAX_PREEDIT_CHAR_NUM              256
00113 #define MAX_CANDIDATE_CHAR_NUM            256
00114 #define MAX_STATUS_CHAR_NUM               256
00115 #define MAX_COMMIT_CHAR_NUM               512
00116 #define MAX_LINE_LEN               1024
00117 
00118 #define MAX_KEYMAP_KEY_NUM         95
00119 
00120 #define IME_PREEDIT_AREA           1
00121 #define IME_LOOKUP_AREA            2
00122 #define IME_STATUS_AREA            4
00123 #define IME_COMMIT                 8
00124 
00125 #define ENGINE_NOT_INSTALLED              1
00126 #define ENGINE_NOT_INITIATED              2
00127 #define ENGINE_INITIATED                  3
00128 
00129 #define DEFAULT_ENGINE_PATH        IIIMLEDIR
00130 #define DEFAULT_DICT_PATH          "data"
00131 #define COMMON_ENGINE_PATH         "common"
00132 #define DEFAULT_LOCALE_PATH        "locale"
00133 #define GENERIC_IM_TABLE_NAME    "GENERIC_IM_TABLE"
00134 #define SWITCH_TO_NEXT_LOCALE    "SWITCH_TO_NEXT_LOCALE"
00135 #define SWITCH_TO_PREV_LOCALE    "SWITCH_TO_PREV_LOCALE"
00136 #define SWITCH_LAYOUT_NAME    "SWITCH_LAYOUT"
00137 #define CODETABLE_ENGINE_NAME      "ctim"
00138 #define USER_PROFILE_PATH                 ".Xlocale"
00139 #define USER_PROFILE_NAME                 "ime.cfg"
00140 #define SYSTEM_PROFILE_NAME        "sysime.cfg"
00141 #define HOTKEY_CONFIG_FILE         "hotkey_config.xml"
00142 #define USER_OPTION_FILE_NAME             "options.cfg"
00143 #define VAR_LE_DIR                 "/var/lib/iiim/le"
00144 
00145 #define NUMERIC_LABEL                     0
00146 #define LOWER_LABEL                1
00147 #define UPPER_LABEL                2
00148 
00149 #define MAX_ENGINE_NUM                    127
00150 #define MAX_NAME_LEN               16
00151 
00152 #define MAX_ARGS_NUM               10
00153 
00154     /***************************************************************************/
00155     /*         Protocol used by Auxiliary window and Language Engine           */
00156     /***************************************************************************/
00157     /* Conversion Status */
00158 #define CONVERSION_OFF                    0
00159 #define CONVERSION_ON                     1
00160 
00161     /* Types of Input Method Switching */
00162 #define IME_ROUND_SWITCH           0
00163 #define IME_SELECT_SWITCH          1
00164 
00165     /* Protocol Number between Auxiliary Window and Language Engine */
00166     /* For PaletteAux */
00167 #define PALETTEAUX_CONNECT                1
00168 #define PALETTEAUX_SWITCH_CONVERSION             2
00169 #define PALETTEAUX_SWITCH_IME                    3
00170 #define PALETTEAUX_CHANGE_POSITION        6
00171 #define PALETTEAUX_SHOW_OPTIONAUX         7
00172 #define PALETTEAUX_SHOW_SELECTAUX         8
00173 #define PALETTEAUX_SHOW_KEYBOARDAUX              9
00174 #define PALETTEAUX_SHOW_LOOKUPAUX         10
00175 #define PALETTEAUX_START_ACTION                  11
00176 
00177 #define PALETTEAUX_UPDATE_IMEINFO_NOTIFY  12
00178 #define PALETTEAUX_SWITCH_CONVERSION_NOTIFY      13
00179 #define PALETTEAUX_SWITCH_IME_NOTIFY             14
00180 
00181     /* For Common used protocol */
00182 #define COMMONAUX_COMMIT_KEY                     20
00183 #define COMMONAUX_COMMIT_STRING                  21
00184 #define COMMONAUX_UPDATE_OPTIONSINFO             22
00185 #define COMMONAUX_LOST_FOCUS                     23
00186 
00187 #define COMMONAUX_CHANGE_FOCUS_NOTIFY            24
00188 #define COMMONAUX_UPDATE_KEYMAPINFO_NOTIFY       25
00189 #define COMMONAUX_SET_IME_NEW_NOTIFY             26
00190 #define COMMONAUX_SET_IME_INFO_NOTIFY            27
00191 #define COMMONAUX_SET_IME_END_NOTIFY             28
00192 
00193     /* For OptionAux */
00194 #define OPTIONAUX_CONNECT                 30
00195 #define OPTIONAUX_CHANGE_STATUS                  31
00196 
00197 #define OPTIONAUX_SHOW_NOTIFY                    32
00198 #define OPTIONAUX_HIDE_NOTIFY                    33
00199 #define OPTIONAUX_UPDATE_ARGS_NEW_NOTIFY  34
00200 #define OPTIONAUX_UPDATE_ARGS_INFO_NOTIFY 35
00201 
00202     /* For SelectAux */
00203 #define SELECTAUX_CONNECT                 40
00204 #define SELECTAUX_UPDATE_IMEINFO          41
00205 #define SELECTAUX_CHANGE_STATUS                  42
00206 
00207 #define SELECTAUX_SHOW_NOTIFY                    43
00208 #define SELECTAUX_HIDE_NOTIFY                    44
00209 
00210     /* For KeyboardAux */
00211 #define KEYBOARDAUX_CONNECT               50
00212 #define KEYBOARDAUX_CHANGE_POSITION              51
00213 #define KEYBOARDAUX_CHANGE_KEY_STATUS            52
00214 
00215 #define KEYBOARDAUX_SHOW_NOTIFY                  53
00216 #define KEYBOARDAUX_HIDE_NOTIFY                  54
00217 #define KEYBOARDAUX_PRESS_KEY_NOTIFY             55
00218 
00219     /* For LookupAux */
00220 #define LOOKUPAUX_CONNECT                 60
00221 #define LOOKUPAUX_CHANGE_STATUS                  61
00222 #define LOOKUPAUX_CHANGE_POSITION         62
00223 
00224 #define LOOKUPAUX_SHOW_NOTIFY                    63
00225 #define LOOKUPAUX_HIDE_NOTIFY                    64
00226 
00227     /* For ActionAux */
00228 #define ACTIONAUX_CONNECT                 70
00229 #define ACTIONAUX_START_ACTION_NOTIFY            71
00230 
00231 enum IME_HOTKEY_STATUS {
00232   IME_HOTKEY_START = 0,
00233   IME_HOTKEY_END,
00234   IME_HOTKEY_NOT_IN_USE,
00235   IME_HOTKEY_COMMIT,
00236 };
00237 
00238 enum IME_HOTKEY_PROFILE_ID {
00239   IME_HOTKEY_PROFILE_ONE = 1,
00240   IME_HOTKEY_PROFILE_TWO,
00241   IME_HOTKEY_PROFILE_THREE,
00242   IME_HOTKEY_PROFILE_NUM,
00243 };
00244 
00245     /***************************************************************************/
00246     /*                 IME structure used by Language Engine                   */
00247     /***************************************************************************/
00248     typedef struct {
00249       int            encode;
00250       int            inputkey_len;
00251       int            preedit_len;
00252       int            lookup_num;
00253       int            commit_len;
00254       int            status_len;
00255       int            *inputkey_buf;       /* buffer for input keys */
00256       unsigned char  *commit_buf;         /* buffer for commit string */
00257       unsigned char         *preedit_buf;        /* buffer for preedit area */
00258       unsigned char         *prev_preedit_buf;          /* temporary preedit buffer */
00259       unsigned char  *status_buf;         /* buffer for status area  */
00260       unsigned char  **lookup_buf;        /* buffer for lookup area  */
00261       unsigned char  **candidates_buf;    /* buffer for candidates strings    */
00262       unsigned char  **additions_buf;     /* buffer for candidates additions  */
00263 
00264       int            preedit_caretpos;
00265       int            cur_lookup_pos;
00266       CARD8          lookup_label_type;
00267       CARD8          return_status;
00268 
00269       unsigned short session_id;    
00270       int            hotkey_flag;
00271       int            conv_flag;
00272     } IMEBufferRec, *IMEBuffer;
00273        
00274 /* IMEBaseRec that shared between Language Engine and Auxiliary WIndow. */
00275 typedef struct {
00276   CARD8              engine_id;           /* engine identity */
00277   CARD8              locale_id;           /* supported locale idendity */
00278   CARD8              encode_id;           /* encode that dictionary used */
00279   CARD8              status;                     /* engine status: initialized or installed */
00280   char        *ename;              /* English name of this engine */
00281   char    *lname;
00282   char               *cname;                     /* Name of this engine */
00283 } IMEBaseRec, *IMEBase;
00284 
00285 /* Arguments:
00286    system arguments ---> IMECoreRec
00287    user defined arguments   ---> Desktop_data
00288 */
00289 typedef struct {
00290   char        *name;
00291   CARD8              type;
00292   CARD8              value;
00293 } IMEArgRec, *IMEArg;
00294        
00295 typedef struct { 
00296   int         args_num;
00297   IMEArgRec   args[MAX_ARGS_NUM];
00298 } IMEArgListRec, *IMEArgList;
00299 
00300 /* Runtime Environment */
00301 typedef struct { 
00302   CARD8              output_encode_id;    /* encode that IME need output */
00303   char               *lang_name;          
00304   char               *locale_name;        /* locale name defined in config file */
00305   char               *data_path;          /* directory for dictionary */
00306   char               *data_ptr;           /* memory pointer for dictionary data */
00307 } IMEEnvListRec, *IMEEnvList;
00308 
00309 /* Keymap Information */
00310 typedef struct {
00311   char               bSet;                /* whether be set by IM engine */
00312   char               *keymap[MAX_KEYMAP_KEY_NUM];
00313 } IMEKeyMapRec, *IMEKeyMap;
00314 
00315 /* IME Core Information */
00316 typedef struct {
00317   IMEBaseRec  baseinfo;            /* Input Method Entry information */
00318   IMEEnvListRec      envinfo;             /* runtime environment of IME engine */
00319   IMEArgListRec      argsinfo;            /* system arguments setting */
00320   IMEKeyMapRec       keymapinfo;          /* key mapping for the IM */
00321 } IMECoreRec, *IMECore;
00322 
00323 typedef struct {
00324   int                keyCode;
00325   int         keyChar;
00326   int         modifier;
00327 } IMEKeyRec, *IMEKey;
00328 
00329 typedef struct _method_t {
00330   int  (*IME_SetOptions)(IMECore, char *);
00331   int  (*IME_SetValues)(IMECore, IMEArgList, int);
00332   int  (*IME_Init)(IMECore);
00333   int  (*IME_Open)(IMECore, IMEBuffer, void *);
00334   int  (*IME_Filter)(IMECore, IMEKey, IMEArgList, IMEBuffer);
00335   void (*IME_Close)(IMECore);
00336 } IMEMethodsRec, *IMEMethods;
00337 
00338 typedef struct {
00339   IMECoreRec  core;
00340   IMEMethods  so_methods;
00341   void        *so_handler;
00342 } IMEEngineRec, *IMEEngine;
00343 
00344 typedef struct {
00345   int         nIME_Num;
00346   IMEBaseRec  *arrIME_Base[MAX_ENGINE_NUM];
00347 } IMEListRec;
00348 
00349 typedef struct {
00350   char *locale_name;
00351   int firstEngineId;
00352   int lastEngineId;
00353   int nEngineId;
00354 }LocaleList;
00355 
00356 /* Mode List */
00357 typedef struct {
00358   char *locale_name;
00359   char *nlocale_name;
00360   char *nlayout_name;
00361   char *engine_name;
00362   int engine_id;
00363   char *default_state;      
00364 }IMEModeList;
00365 
00366 typedef struct KEY_VALUE_PAIR_ {
00367   char *key_name;
00368   int value;
00369 }keyvalue_pair;
00370 
00371 /* UNIT DESKTOP DATA STRUCTURE */
00372 
00373 typedef struct _unit_desktop_t {
00374   /* public */
00375   void (*unit_desktop_init) ();
00376   int (*unit_desktop_add_listener) ();
00377   int (*unit_desktop_load_engines) ();
00378   void (*unit_desktop_set_curr_profile_id) ();
00379   int (*unit_desktop_get_curr_profile_id) ();
00380   void (*unit_desktop_switch_hotkey_profile) ();
00381   void (*unit_desktop_done) ();
00382 
00383   /* private */ 
00384   iml_session_t   *s;
00385   int             gEngine_Num;
00386   int             locale_Num;
00387   int             nextLocaleKeycode;
00388   int             nextLocaleModifier;
00389   int             prevLocaleKeycode;
00390   int             prevLocaleModifier;
00391   int             layoutNameKeyCode;
00392   int             layoutNameModifier;
00393   int             curr_hotkey_profile_id;
00394   IMEEngineRec    *gEngine_Info[MAX_ENGINE_NUM];
00395   IMEModeList     *modeList[MAX_ENGINE_NUM];
00396   LocaleList      *localeList; 
00397   struct _unit_desktop_t *next;
00398 } unit_desktop_t;
00399 
00400 typedef unit_desktop_t *unit_desktop_list;
00401 
00402 /* UNIT INTERFACE DATA STRUCTURE */
00403 
00404 typedef struct _unit_if_t {
00405   /* public */
00406   unit_desktop_t * (*get_current_unit_desktop) ();
00407   unit_desktop_t * (*create_unit_desktop) ();
00408   int (*destory_unit_desktop) (unit_desktop_t *);
00409   void (*add_unit_desktop) (unit_desktop_t *);
00410   unit_desktop_t * (*find_unit_desktop_by_sc) (iml_session_t *);
00411 
00412   /* private */ 
00413   unit_desktop_list ud_list;
00414   int ud_count;
00415   void *ptr;
00416 } unit_if_t;
00417 
00418 #endif   /* _UNITINPUT_H_  */