Back to index

im-sdk  12.3.91
Classes | Defines | Typedefs | Functions | Variables
ctim_interface.c File Reference
#include <stdio.h>
#include "ctim.h"
#include "ctim_messages.h"

Go to the source code of this file.


struct  _codetable_im_data_t


#define NAME_UTF8   "Codetable"
#define AUTHOR   "Ervin Yan <>"
#define COPYRIGHT   "Copyright (c) 2005 Sun Microsystems"
#define HINTING   "Codetable Input Method"


typedef struct _codetable_im_data_t codetable_im_data_t


ImeResult ctim_Initialize (ImeInfo ime_info)
ImeResult ctim_Destroy (ImeInfo ime_info)
ImeResult ctim_Process_Key_Event (ImeInputContext ic, ImeKey key_event)
ImeResult ctim_Create_Session (ImeInputContext ic)
ImeResult ctim_Destroy_Session (ImeInputContext ic)
ImeResult ctim_FocusOut (ImeInputContext ic)
ImeResult ctim_FocusIn (ImeInputContext ic)
ImeResult RegisterIME (ImmServices srvs, ImeInfo *ppinfo, ImeMethods *pmthds, int argc, char **argv)
ImmResult ctim_beep (ImeInputContext ic)
ImmResult ctim_commit (ImeInputContext ic, int encoding, char *commit_buf, int commit_len)
ImmResult ctim_update_preedit (ImeInputContext ic, int encoding, char *preedit_buf, int preedit_len, int caret_pos)
ImmResult ctim_update_candidates (ImeInputContext ic, int encoding, int label_type, char **candidates, int num_candidates, int page_state)


ImmServices imm_services
ImeMethodsRec ctim_methods

Class Documentation

struct _codetable_im_data_t

Definition at line 25 of file ctim_interface.c.

Collaboration diagram for _codetable_im_data_t:
Class Members
CodeTableStruct * ctHeader
char * file_name
TZhuyinData * zhuyin_data

Define Documentation

#define AUTHOR   "Ervin Yan <>"

Definition at line 11 of file ctim_interface.c.

#define COPYRIGHT   "Copyright (c) 2005 Sun Microsystems"

Definition at line 12 of file ctim_interface.c.

#define HINTING   "Codetable Input Method"

Definition at line 13 of file ctim_interface.c.

#define NAME_UTF8   "Codetable"

Definition at line 10 of file ctim_interface.c.

Typedef Documentation

Function Documentation

Definition at line 283 of file ctim_interface.c.

       return (imm_services->ImmBeep(ic, ImeBeepWarning));
ImmResult ctim_commit ( ImeInputContext  ic,
int  encoding,
char *  commit_buf,
int  commit_len 

Definition at line 288 of file ctim_interface.c.

        if (commit_len <= 0)
                return (IMM_FAIL);

        if (commit_buf == NULL)
                return (IMM_FAIL);

        return (imm_services->ImmCommit(ic, commit_buf));
ImmResult ctim_update_candidates ( ImeInputContext  ic,
int  encoding,
int  label_type,
char **  candidates,
int  num_candidates,
int  page_state 

Definition at line 317 of file ctim_interface.c.

        int i;
        ImmResult imm_result;
        ImeCandidatesRec       ime_candidates;

        memset(&ime_candidates, 0, sizeof(ImeCandidatesRec));

        if (num_candidates == 0 || candidates == NULL) {
                return (imm_services->ImmHideCandidates(ic));


        ime_candidates.title = NULL;
        ime_candidates.focus = 0;
       ime_candidates.page_state = page_state;

        ime_candidates.numbers = NULL;
        switch (label_type) {
        case NUMBER0_MODE:
                ime_candidates.numbers = "0123456789abcdefghijklmnopqrstuvwxyz";
        case NUMBER_MODE:
                ime_candidates.numbers = "1234567890abcdefghijklmnopqrstuvwxyz";
        case LOWER_MODE:
                ime_candidates.numbers = "abcdefghijklmnopqrstuvwxyz";
        case UPPER_MODE:
                ime_candidates.numbers = "ABCDEFGHIJKLMNOPQRSTUVWXYZ";

        ime_candidates.count = num_candidates;
        ime_candidates.candidates = (ImeTextRec *)calloc(num_candidates, sizeof(ImeTextRec));
        if (ime_candidates.candidates == NULL)
                return (IMM_FAIL);

        for (i=0; i<num_candidates; i++) {
                ime_candidates.candidates[i].text = candidates[i];

        imm_result = imm_services->ImmUpdateCandidates(ic, &ime_candidates);

       free ((char *)ime_candidates.candidates);

ImmResult ctim_update_preedit ( ImeInputContext  ic,
int  encoding,
char *  preedit_buf,
int  preedit_len,
int  caret_pos 

Definition at line 299 of file ctim_interface.c.

        ImePreeditRec ime_preedit;
        memset(&ime_preedit, 0, sizeof(ImePreeditRec));

        if (preedit_len == 0) {
                return (imm_services->ImmHidePreedit(ic));


        ime_preedit.cl_start = ime_preedit.caret = caret_pos;
        ime_preedit.preedit.text     = preedit_buf;

        return (imm_services->ImmUpdatePreedit(ic, &ime_preedit));
ImeResult RegisterIME ( ImmServices  srvs,
ImeInfo ppinfo,
ImeMethods pmthds,
int  argc,
char **  argv 

Definition at line 54 of file ctim_interface.c.

        ImeInfoRec *ctim_info = NULL;
        char *codetable_file_name = NULL;
        char *base_dir = NULL;
        char file_path[256];
        CodeTableStruct ctHeader;
        codetable_im_data_t *ctim_data = NULL;

        int version_num, i, ret;

        DEBUG_printf("Register Codetable IM: argc: %d\n", argc);
        for (i=0; i<argc; i++) {
                if (!strcasecmp(argv[i], "-basedir")) {
                        if (argv[i+1]) {
                                base_dir = argv[i+1];
                                DEBUG_printf("       setting base dir to: %s\n", argv[i+1]);
                } else if (!strcasecmp(argv[i], "-codetable")) {
                        if (argv[i+1]) {
                                codetable_file_name = argv[i+1];
                                DEBUG_printf("       setting codetable file to: %s\n", argv[i+1]);

        if (!codetable_file_name || !*codetable_file_name)
                return (IME_FAIL);

        if (base_dir == NULL)
                base_dir = LE_BASE_DIR;

        if (base_dir && *base_dir && *codetable_file_name != '/') {
                snprintf(file_path, 256, "%s/%s", base_dir, codetable_file_name);

        DEBUG_printf("file_path: %s\n", file_path);
        ret = LoadCodeTableHeader(file_path, &ctHeader);
        if (ret == -1)
                return (IME_FAIL);

        ctim_data = (codetable_im_data_t *)calloc(1, sizeof(codetable_im_data_t));
        if (ctim_data == NULL)
                return (IME_FAIL);

        ctim_info = (ImeInfoRec *)calloc(1, sizeof(ImeInfoRec));
        if (ctim_info == NULL)  {
                free ((char *)ctim_data);
                return (IME_FAIL);

        version_num = 1;
        if (*(ctHeader.Version))
                version_num = atoi(ctHeader.Version);
        version_num += CODETABLE_VERSION * 100;

        ctim_info->version           = version_num;
        ctim_info->encoding          = ctHeader.Encode;
        ctim_info->name              = (char *)strdup(ctHeader.Cname);
        ctim_info->uuid              = (char *)strdup(ctHeader.UUID);

        if (*ctHeader.Author)
                ctim_info->author    = (char *)strdup(ctHeader.Author);
                ctim_info->author    = (char *)strdup(AUTHOR);
        if (*ctHeader.Copyright)
                ctim_info->copyright = (char *)strdup(ctHeader.Copyright);
                ctim_info->copyright = (char *)strdup(COPYRIGHT);
        if (*ctHeader.Hinting)
                ctim_info->hinting   = (char *)strdup(ctHeader.Hinting);
                ctim_info->hinting   = (char *)strdup(HINTING);

        ctim_info->icon_file         = (char *)strdup(ctHeader.IconPath);

        ctim_info->support_locales = CTIM_SUPPORT_LOCALES;

        ctim_data->file_name = (char *)strdup(file_path);
        ctim_data->ctHeader  = NULL;

        ctim_info->specific_data     = (void *)ctim_data;

        *ppinfo = ctim_info;
        *pmthds = &ctim_methods;

        imm_services = srvs;

        DEBUG_printf("begin leave Register IME\n");
        return (IME_OK);

Here is the call graph for this function:

Variable Documentation

Definition at line 23 of file ctim_interface.c.