Back to index

im-sdk  12.3.91
array_properties.c
Go to the documentation of this file.
00001 #include <stdio.h>
00002 
00003 #ifdef HAVE_CONFIG_H
00004 #include "config.h"
00005 #endif
00006 
00007 #include "ctim.h"
00008 #include "ctim_messages.h"
00009 
00010 ImePropertyRec ctim_options[] = {
00011 #if 0
00012     { KEYBYKEY_MODE_ID,   ENCODE_UTF8, "/input_style",    KEYBYKEY_MODE_STR, NULL, ImeProperty_Toggle, {0, 0}, 0},
00013     { HELPINFO_MODE_ID,   ENCODE_UTF8, "/codehinting",    HELPINFO_MODE_STR,   NULL, ImeProperty_Toggle, {0, 0}, 0},
00014     { AUTOSELECT_MODE_ID, ENCODE_UTF8, "/singleselect",   AUTOSELECT_MODE_STR, NULL, ImeProperty_Toggle, {0, 0}, 1},
00015     { KEYPROMPT_MODE_ID,  ENCODE_UTF8, "/keyprompt",      KEYPROMPT_MODE_STR, NULL, ImeProperty_Toggle, {0, 0}, 0},
00016 #endif
00017     { KEYMAPPING_MODE_ID, ENCODE_UTF8, "/keymapping",     KEYMAPPING_MODE_STR, NULL, ImeProperty_Selection, {0, 0}, 0},
00018 };
00019 
00020 ImePropertyListRec ctim_optionlist = {
00021     sizeof(ctim_options)/sizeof(ImePropertyRec),
00022     ctim_options
00023 };
00024 
00025 extern ImmServices imm_services;
00026 
00027 char *ctim_get_keymapping_string(CodeTableStruct *ctHeader)
00028 {
00029        int i;
00030         char *keymapping_str = NULL;
00031 
00032         if (ctHeader == NULL || ctHeader->keyprompt == NULL)
00033               return NULL;
00034 
00035        if (GETBIT(ctHeader->bSectionsFlag, KEYPROMPT_SECTION)) {
00036               int buf_len = 0;
00037               int item_num = 0;
00038               char ch;
00039 
00040               char *prefix = "keymapping:/default";
00041 
00042               for (i = 0; i < MAX_USEDCODES_NUM; i ++) {
00043                      ch = ctHeader->UsedCodes[i];
00044 
00045                      if (ch == 0) break;
00046 
00047                      if (ctHeader->keyprompt[ch].prompt[0] != 0) {
00048                             item_num ++;
00049                             buf_len += strlen (ctHeader->keyprompt[ch].prompt);
00050                             DEBUG_printf("%c: %s\n", ch, ctHeader->keyprompt[ch].prompt);
00051                      }
00052               }
00053 
00054               if (buf_len > 0) {
00055                      buf_len += (item_num * 2 + strlen (prefix)) + 3;
00056 
00057                      keymapping_str = (char *)calloc (1, buf_len);
00058                      snprintf(keymapping_str, buf_len, "%s", prefix);
00059 
00060                      for (i = 0; i < MAX_USEDCODES_NUM; i ++) {
00061                             char key_str[256];
00062 
00063                             ch = ctHeader->UsedCodes[i];
00064                             if (ch == 0) break;
00065 
00066                             if (ctHeader->keyprompt[ch].prompt[0] != 0) {
00067                                    char *format_str = "|%c%s";
00068                                    if (ch == '/' || ch == '|') {
00069                                           format_str = "|\\%c%s";
00070                                    }
00071                                    snprintf(key_str, 256, format_str,
00072                                            ch, ctHeader->keyprompt[ch].prompt);
00073                                    strncat(keymapping_str, key_str, buf_len);
00074                             }
00075                      }
00076                      DEBUG_printf("keymapping_str: %s\n", keymapping_str);
00077                 }
00078        }
00079 
00080        return keymapping_str;
00081 }
00082 
00083 ImeResult ctim_Init_Ime_Properties(ImeInfoRec *ctim_info, CodeTableStruct *ctHeader)
00084 {
00085 #if 0
00086        int i;
00087        ImePropertyListRec *pl;
00088 
00089        if (ctim_info == NULL || ctHeader == NULL)
00090               return (IME_FAIL);
00091 
00092        DEBUG_printf("ctim_Init_Ime_Properties\n");
00093 
00094        pl = (ImePropertyListRec *)calloc(1, sizeof (ImePropertyListRec));
00095        if (pl == NULL)
00096               return (IME_FAIL);
00097 
00098        pl->properties = (ImePropertyRec *)calloc (CTIM_ARGS_NUM, sizeof(ImePropertyRec));
00099        if (pl->properties == NULL) {
00100               free ((char *) pl);
00101               return (IME_FAIL);
00102        }
00103 
00104        pl->count = CTIM_ARGS_NUM;
00105        for (i = 0; i < CTIM_ARGS_NUM; i ++) {
00106               ImePropertyRec *pi = &(pl->properties[i]);
00107 
00108               pi->id = ctim_options[i].id;
00109               pi->encode = ctim_options[i].encode;
00110               pi->key = ctim_options[i].key;
00111               pi->name = ctim_options[i].name;
00112               pi->tip = ctim_options[i].tip;
00113               pi->type = ctim_options[i].type;
00114               pi->range = ctim_options[i].range;
00115        }
00116 
00117        pl->properties[KEYBYKEY_MODE_ID].value.int_value = ctHeader->nKeyByKeyMode;
00118        pl->properties[HELPINFO_MODE_ID].value.int_value = ctHeader->nHelpInfoMode;
00119        pl->properties[AUTOSELECT_MODE_ID].value.int_value = ctHeader->nAutoSelectMode;
00120        pl->properties[KEYPROMPT_MODE_ID].value.int_value = ctHeader->nKeyPromptMode;
00121 #endif
00122 
00123        ctim_options[0].encode = ctHeader->Encode;
00124        ctim_options[0].name = (char *)ctim_get_keymapping_string(ctHeader);
00125        ctim_options[0].value.int_value = 0;
00126 
00127        ctim_info->pl = (ImePropertyListRec *)(&ctim_optionlist);
00128 
00129        return (IME_OK);
00130 }
00131 
00132 ImeResult ctim_Destroy_Ime_Properties(ImeInfoRec *ctim_info)
00133 {
00134 #if 0
00135        if (ctim_info == NULL)
00136               return (IME_FAIL);
00137 
00138        DEBUG_printf("ctim_Destroy_Ime_Properties\n");
00139 
00140        if (ctim_info->pl) {
00141               if (ctim_info->pl->properties)
00142                      free ((char *) ctim_info->pl->properties);
00143               free ((char *) ctim_info->pl);
00144        }
00145 #endif
00146 
00147        if (ctim_options[0].name)
00148               free ((char *)ctim_options[0].name);
00149        ctim_options[0].name = NULL;
00150 
00151        return (IME_OK);
00152 }
00153 
00154 ImeResult ctim_Set_Ime_Properties(ImeInputContext ic, CodeTableStruct *ctHeader)
00155 {
00156 #if 0
00157        int i;
00158        ImePropertyListRec *pl;
00159        ImePropertyRec *pi;
00160 
00161        DEBUG_printf("ctim_Set_Ime_Properties\n");
00162 
00163        if (ctHeader == NULL)
00164               return (IME_FAIL);
00165 
00166         pl = imm_services->ImmGetPropertyList(ic);
00167        if (pl != NULL && pl->count > 0 && pl->properties != NULL) {
00168               for (i = 0; i < pl->count; i++) {
00169                      pi = &(pl->properties[i]);
00170                      switch (pi->id) {
00171                      case KEYBYKEY_MODE_ID:
00172                             ctHeader->nKeyByKeyMode =  pi->value.int_value;
00173                             break;
00174                      case HELPINFO_MODE_ID:
00175                             ctHeader->nHelpInfoMode = pi->value.int_value;
00176                             break;
00177                      case AUTOSELECT_MODE_ID:
00178                             ctHeader->nAutoSelectMode = pi->value.int_value;
00179                             break;
00180                      case KEYPROMPT_MODE_ID:
00181                             ctHeader->nKeyPromptMode = pi->value.int_value;
00182                             break;
00183                      }
00184               }
00185        }
00186 #endif
00187 
00188         ctHeader->nKeyByKeyMode = 0;
00189         ctHeader->nHelpInfoMode = 0;
00190         ctHeader->nAutoSelectMode = 1;
00191         ctHeader->nKeyPromptMode = 1;
00192 
00193        return (IME_OK);
00194 }