Back to index

im-sdk  12.3.91
chewing_properties.c
Go to the documentation of this file.
00001 #include <stdio.h>
00002 
00003 #include "ime.h"
00004 #include "chewing_im.h"
00005 
00006 #if 0
00007 #define KB_DEFAULT_STR       "¼Ð·ÇÁä½L"
00008 #define KB_HSU_STR           "³\¤óÁä½L"
00009 #define KB_IBM_STR           "IBM Áä½L"
00010 #define KB_GIN_YIEH_STR      "ºë·~Áä½L"
00011 #define KB_ET_STR            "­Ê¤ÑÁä½L"
00012 #define KB_ET26_STR          "­Ê¤Ñ26Áä½L"
00013 #define KB_DVORAK_STR        "Dvorak Áä½L"
00014 #define KB_DVORAK_HSU_STR    "Dvorak + ³\¤óÁä½L"
00015 
00016 #define CHEWING_KEYMAP_MODE_STR     "Áä½L±Æ¦C¤è¦¡¡G"
00017 #endif
00018 
00019 #define CHEWING_KEYMAP_MODE_ID      0
00020 
00021 char kb_default_str[] = { 0xbc,0xd0,0xb7,0xc7,0xc1,0xe4,0xbd,0x4c,0 };
00022 char kb_hsu_str[] = { 0xb3,0x5c,0xa4,0xf3,0xc1,0xe4,0xbd,0x4c,0 };
00023 char kb_ibm_str[] = { 0x49,0x42,0x4d,0x20,0xc1,0xe4,0xbd,0x4c,0 };
00024 char kb_gin_yieh_str[] = { 0xba,0xeb,0xb7,0x7e,0xc1,0xe4,0xbd,0x4c,0 };
00025 char kb_et_str[] = { 0xad,0xca,0xa4,0xd1,0xc1,0xe4,0xbd,0x4c,0 };
00026 char kb_et26_str[] = { 0xad,0xca,0xa4,0xd1,0x32,0x36,0xc1,0xe4,0xbd,0x4c,0 };
00027 char kb_dvorak_str[] = { 0x44,0x76,0x6f,0x72,0x61,0x6b,0x20,0xc1,0xe4,0xbd,0x4c,0 };
00028 char kb_dvorak_hsu_str[] = { 0x44,0x76,0x6f,0x72,0x61,0x6b,0x20,0x2b,0x20,0xb3,0x5c,0xa4,0xf3,0xc1,0xe4,0xbd,0x4c,0 };
00029 char chewing_keymap_mode_str[] = { 0xc1,0xe4,0xbd,0x4c,0xb1,0xc6,0xa6,0x43,0xa4,0xe8,0xa6,0xa1,0xa1,0x47,0 };
00030 
00031 char **KeymappingOptions = NULL;
00032 
00033 ImePropertyRec chewing_options[] = {
00034     {CHEWING_KEYMAP_MODE_ID, ENCODE_BIG5, "/keymapping",
00035      chewing_keymap_mode_str, NULL, ImeProperty_Selection, {0, 0}, 0},
00036 };
00037 
00038 ImePropertyListRec chewing_optionlist = {
00039     sizeof(chewing_options) / sizeof(ImePropertyRec),
00040     chewing_options
00041 };
00042 
00043 extern ImmServices imm_services;
00044 
00045 char *chewing_get_keymapping_str(int kb_type)
00046 {
00047     int i, buf_len;
00048     char pho[16]; 
00049     char key[2];
00050     int  ret;
00051     int  searchTimes = 0;
00052     char *keymapping_str = NULL;
00053 
00054     char *valid_keys = "abcdefghijklmnopqrstuvwxyz0123456789-=[]\\;',./";
00055 
00056     char *kb_strs[KB_TYPE_NUM + 1] = {
00057         kb_default_str,
00058         kb_hsu_str,
00059         kb_ibm_str,
00060         kb_gin_yieh_str,
00061         kb_et_str,
00062         kb_et26_str,
00063         kb_dvorak_str,
00064         kb_dvorak_hsu_str,
00065         NULL,
00066     };
00067 
00068     if (kb_type < 0 || kb_type >= KB_TYPE_NUM - 1)
00069         return (NULL);
00070 
00071     buf_len = strlen(kb_strs[kb_type]);
00072     for (i = 0; i < strlen(valid_keys); i++) {
00073         memset (pho, 0, 6);
00074         key[0] = *(valid_keys + i);
00075         key[1] = 0;
00076         searchTimes = 1;
00077         ret = Key2Pho(pho, key, kb_type, searchTimes);
00078         if (ret == 0)
00079             continue;
00080 
00081         buf_len += strlen(pho) + 2;
00082     }
00083 
00084     keymapping_str = (char *)calloc (buf_len + 3, sizeof (char));
00085     if (keymapping_str == NULL)
00086         return (NULL);
00087 
00088     snprintf(keymapping_str, buf_len, "%s", kb_strs[kb_type]);
00089 
00090     for (i = 0; i < strlen(valid_keys); i++) {
00091         char ch = *(valid_keys + i);
00092         char *format_str = "|%c%s";
00093         char key_str[256];
00094 
00095         memset (pho, 0, 16);
00096         key[0] = ch;
00097         key[1] = 0;
00098 
00099         searchTimes = 1;
00100         ret = Key2Pho(pho, key, kb_type, searchTimes);
00101         if (ret == 0 || pho[0] == 0)
00102             continue;
00103 
00104         if (ch == '/' || ch == '|')
00105             format_str = "|\\%c%s";
00106 
00107         snprintf(key_str, 256, format_str, ch, pho);
00108         strncat(keymapping_str, key_str, buf_len);
00109     }
00110 
00111     DEBUG_printf("keymapping_str: %s\n", keymapping_str);
00112     return (keymapping_str);
00113 }
00114 
00115 ImeResult chewing_Init_Ime_Properties(ImeInfoRec * chewing_info)
00116 {
00117     int i, num_keymap;
00118 
00119     if (chewing_info == NULL)
00120        return (IME_FAIL);
00121 
00122     DEBUG_printf("chewing_Init_Ime_Properties\n");
00123 
00124     if (KeymappingOptions == NULL) {
00125         KeymappingOptions = (char **) calloc (KB_TYPE_NUM + 1, sizeof (char *));
00126         if (KeymappingOptions == NULL)
00127             return (IME_FAIL);
00128 
00129         /* "KB_TYPE_NUM - 1" means we disable KB_HANYU_PINYING for libchewing 0.2.5 */
00130         num_keymap = 0;
00131         for (i = 0; i < KB_TYPE_NUM - 1; i++) {
00132             char *keymapping_str;
00133             keymapping_str = (char *)chewing_get_keymapping_str(i);
00134             if (keymapping_str) {
00135                 KeymappingOptions[num_keymap++] = keymapping_str;
00136             }
00137         }
00138 
00139         if (num_keymap == 0)
00140             return (IME_FAIL);
00141     }
00142 
00143     chewing_options[CHEWING_KEYMAP_MODE_ID].range.multiString_range = KeymappingOptions;
00144     chewing_options[CHEWING_KEYMAP_MODE_ID].value.int_value = 0;
00145 
00146     chewing_info->pl = (ImePropertyListRec *) (&chewing_optionlist);
00147 
00148     return (IME_OK);
00149 }
00150 
00151 ImeResult chewing_Destroy_Ime_Properties(ImeInfoRec * chewing_info)
00152 {
00153     int i;
00154 
00155     if (KeymappingOptions != NULL) {
00156         for (i = 0; i < KB_TYPE_NUM; i++) {
00157             if (KeymappingOptions[i])
00158                 free ((char *) KeymappingOptions[i]);
00159         }
00160         free ((char *)KeymappingOptions);
00161     }
00162 
00163     return (IME_OK);
00164 }
00165 
00166 ImeResult chewing_Set_Ime_Properties(ImeInputContext ic,
00167                                  chewing_session_t * chewing_session)
00168 {
00169     int i;
00170     ImePropertyListRec *pl;
00171     ImePropertyRec *pi;
00172 
00173     DEBUG_printf("chewing_Set_Ime_Properties\n");
00174 
00175     if (chewing_session == NULL)
00176        return (IME_FAIL);
00177 
00178     chewing_session->keyboard_type = KB_DEFAULT;
00179 
00180     pl = imm_services->ImmGetPropertyList(ic);
00181     if (pl != NULL && pl->count > 0 && pl->properties != NULL) {
00182        for (i = 0; i < pl->count; i++) {
00183            pi = &(pl->properties[i]);
00184            switch (pi->id) {
00185            case CHEWING_KEYMAP_MODE_ID:
00186               chewing_session->keyboard_type = pi->value.int_value;
00187               break;
00188            }
00189        }
00190     }
00191 
00192     return (IME_OK);
00193 }