Back to index

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

Go to the source code of this file.

Classes

struct  language_name_pair_t

Defines

#define M17N_IM_LIST_NUM_ALLOC   10

Functions

LeResult le_info_destroy (LeInfoRec *le_info)
LeResult le_info_init_m17n_input_methods (LeInfoRec *le_info)
LeResult le_info_done_m17n_input_methods (LeInfoRec *le_info)
void le_session_ui_callbacks (MInputContext *ic, MSymbol command)
LeInfoRecle_info_new ()
LeResult le_info_print (LeInfoRec *le_info)
int le_info_pushback_m17n_input_method (LeInfoRec *le_info, M17nImInfoRec *m17n_im)
int le_info_compare_m17n_input_method (const void *elt1, const void *elt2)
LeResult le_info_register_ui_callbacks (MInputMethod *im)
MInputMethod * le_info_get_input_method_for_locale (LeInfoRec *le_info, char *locale)
MInputMethod * le_info_get_next_input_method_for_locale (LeInfoRec *le_info, char *locale, MInputMethod *im)
int le_info_check_language_disabled (LeInfoRec *le_info, char *lang)
char * le_info_get_standard_language_name (char *lang)

Variables

char * disabled_langs []
language_name_pair_t lang_name_pairs []

Class Documentation

struct language_name_pair_t

Definition at line 355 of file le_info.c.

Class Members
char * m17n_lang_name
char * standard_lang_name

Define Documentation

#define M17N_IM_LIST_NUM_ALLOC   10

Definition at line 51 of file le_info.c.


Function Documentation

int le_info_check_language_disabled ( LeInfoRec le_info,
char *  lang 
)

Definition at line 339 of file le_info.c.

{
    int i, num;

    if (!le_info || !lang || !*lang)
        return 0;

    num = sizeof(disabled_langs)/sizeof(char *);
    for (i = 0; i < num; i ++) {
         if (!strcasecmp(lang, disabled_langs[i]))
             return 1;
    }

    return 0;
}

Here is the caller graph for this function:

int le_info_compare_m17n_input_method ( const void *  elt1,
const void *  elt2 
)

Definition at line 86 of file le_info.c.

{
    const M17nImInfoRec *im1 = elt1;
    const M17nImInfoRec *im2 = elt2;
    MSymbol lang1, lang2;

    if (im1->language == Mnil)
        return 1;
    if (im1->language == im2->language)
        return strcmp (msymbol_name (im1->name), msymbol_name (im2->name));
    if (im1->language == Mt)
        return 1;
    if (im2->language == Mt)
        return -1;

    return strcmp (msymbol_name (im1->language), msymbol_name (im2->language));
}

Here is the caller graph for this function:

Definition at line 29 of file le_info.c.

{
    if (le_info == NULL)
       return LE_FAIL;

    le_info_done_m17n_input_methods(le_info);

    free((char *) le_info);

    return LE_OK;
}

Here is the call graph for this function:

Here is the caller graph for this function:

Definition at line 170 of file le_info.c.

{
    int i;
    int num_input_methods;
    M17nImInfoRec **input_methods;

    if (le_info == NULL)
        return LE_OK;

    input_methods = le_info->input_methods;
    num_input_methods = le_info->num_input_methods;
    if (input_methods) {
        for (i = 0; i < num_input_methods; i++) {
             if (input_methods[i]->im)
                 minput_close_im (input_methods[i]->im);
        }
        free ((char *) input_methods);
    }

    mconv_free_converter (le_info->converter);

    M17N_FINI ();

    return LE_OK;
}

Here is the caller graph for this function:

MInputMethod* le_info_get_input_method_for_locale ( LeInfoRec le_info,
char *  locale 
)

Definition at line 221 of file le_info.c.

{
    int i;

    if (le_info == NULL || locale == NULL)
        return ((MInputMethod *)Mnil);

    /* find input method which match the given locale */
    for (i = 0; i < le_info->num_input_methods; i ++) {
        M17nImInfoRec *input_method = le_info->input_methods[i];
        MSymbol m_lang, m_name;
        char *lang;

        if (input_method == NULL)
            continue;

        m_lang = input_method->language;
        m_name = input_method->name;
        if (m_lang == Mt)
            continue;

        lang = msymbol_name(m_lang);
        if (!lang || !*lang)
            continue;

        if (!strncasecmp(locale, lang, strlen(lang))) {
            if (input_method->im == (MInputMethod *)Mnil) {
                input_method->im = minput_open_im(m_lang, m_name, NULL);
                le_info_register_ui_callbacks(input_method->im);
            }
                
            if (input_method->im != (MInputMethod *)Mnil)
                return (input_method->im);
        }
    }

    return ((MInputMethod *)Mnil);
}

Here is the call graph for this function:

Here is the caller graph for this function:

MInputMethod* le_info_get_next_input_method_for_locale ( LeInfoRec le_info,
char *  locale,
MInputMethod *  im 
)

Definition at line 260 of file le_info.c.

{
    int i;

    MSymbol m_lang, m_name;
    M17nImInfoRec *im_info_first = NULL;
    M17nImInfoRec *im_info_current = NULL;
    M17nImInfoRec *im_info_matched = NULL;

    if (le_info == NULL || locale == NULL)
        return ((MInputMethod *)Mnil);

    DEBUG_printf("le_info_get_next_input_method_for_locale: locale: %s, im: %p\n", locale, im);
    /* find input method which match the given locale */
    for (i = 0; i < le_info->num_input_methods; i ++) {
        M17nImInfoRec *input_method = le_info->input_methods[i];
        char *lang;

        if (input_method == NULL)
            continue;

        m_lang = input_method->language;
        m_name = input_method->name;

        lang = msymbol_name(m_lang);
        if (!lang || !*lang)
            continue;

        DEBUG_printf("input_method[%d]: lang: %s, name: %s, im: %p\n",
                i, lang, msymbol_name(m_name), input_method->im);

        if (strncasecmp(locale, lang, strlen(lang)) && m_lang != Mt)
            continue;

        if (im == (MInputMethod *) Mnil) {
            im_info_matched = input_method;
            break;
        }

        if (im_info_first == NULL)
            im_info_first = input_method;

        if (input_method->im == im) {
            im_info_current = input_method;
        } else if (im_info_current != NULL) {
            im_info_matched = input_method;
            break;
        }
    }

    DEBUG_printf("im_info_matched: %p, im_info_first: %p\n", im_info_matched, im_info_first);
    if (im_info_matched == NULL && im_info_first != NULL)
        im_info_matched = im_info_first;

    if (im_info_matched != NULL) {
        if (im_info_matched->im == (MInputMethod *)Mnil) {
            m_lang = im_info_matched->language;
            m_name = im_info_matched->name;

            im_info_matched->im = minput_open_im(m_lang, m_name, NULL);
            le_info_register_ui_callbacks(im_info_matched->im);
        }
        return (im_info_matched->im);
    }
                
    return ((MInputMethod *)Mnil);
}

Here is the call graph for this function:

Here is the caller graph for this function:

char* le_info_get_standard_language_name ( char *  lang)

Definition at line 397 of file le_info.c.

{
    int i, num;

    if (!lang || !*lang)
        return lang;

    num = sizeof(lang_name_pairs)/sizeof(language_name_pair_t);
    for (i = 0; i < num; i ++) {
         char *standard_lang_name;
         char *m17n_lang_name;

         m17n_lang_name = lang_name_pairs[i].m17n_lang_name;
         standard_lang_name =  lang_name_pairs[i].standard_lang_name;

         if (!m17n_lang_name || !*m17n_lang_name)
             continue;

         if (!standard_lang_name || !*standard_lang_name)
             continue;

         if (!strcasecmp(lang, m17n_lang_name)) {
             if (!standard_lang_name || !*standard_lang_name)
                 return lang;
             else
                 return standard_lang_name;
         }
    }

    return lang;
}

Here is the caller graph for this function:

Definition at line 104 of file le_info.c.

{
    MPlist *imlist, *pl;
    MInputMethod *im = NULL;

    int num_input_methods;
    M17nImInfoRec *input_methods;

    M17N_INIT ();
    if (merror_code != MERROR_NONE) {
        fprintf (stderr, "Fail to initialize the m17n library!\n");
       return LE_FAIL;
    }

    le_info->Miiim_ic = msymbol ("iiim_ic");
    le_info->Mkey_english_native = msymbol ("iiim_key_english_native");
    le_info->Mkey_switch_next_im = msymbol ("iiim_key_switch_next_im");

    le_info->converter = mconv_buffer_converter(Mcoding_utf_16, NULL, 0);
    if (!le_info->converter)
        return LE_FAIL;

    imlist = (MPlist *)mdatabase_list (msymbol ("input-method"), Mnil, Mnil, Mnil);
    if (imlist == (MPlist *)Mnil) {
        mconv_free_converter (le_info->converter);
       return LE_FAIL;
    }

    num_input_methods = mplist_length (imlist);
    if (num_input_methods <= 0) {
        mconv_free_converter (le_info->converter);
        m17n_object_unref (imlist);
       return LE_FAIL;
    }

    for (pl = imlist; mplist_key (pl) != Mnil; pl = mplist_next (pl)) {
        MDatabase *mdb = mplist_value (pl);
        MSymbol *tag = mdatabase_tag (mdb);

        if (tag[1] != Mnil) {
            M17nImInfoRec *input_method;

            input_method = (M17nImInfoRec *)calloc(1, sizeof(M17nImInfoRec));
            if (input_method == NULL)
                continue;

            input_method->language = tag[1];
            input_method->name = tag[2];
            input_method->im = NULL;

            DEBUG_printf("lang: %s, name: %s\n",
                         msymbol_name(tag[1]), msymbol_name(tag[2]));
            le_info_pushback_m17n_input_method(le_info, input_method);
        }
    }

    m17n_object_unref (imlist);

    qsort(le_info->input_methods, le_info->num_input_methods,
          sizeof(le_info->input_methods[0]), le_info_compare_m17n_input_method);

    DEBUG_printf("num_input_methods: %d\n", le_info->num_input_methods);

    return LE_OK;
}

Here is the call graph for this function:

Here is the caller graph for this function:

Definition at line 11 of file le_info.c.

{
    LeResult result;
    LeInfoRec *le_info = NULL;

    le_info = (LeInfoRec *) calloc(1, sizeof(LeInfoRec));
    if (le_info == NULL)
       return NULL;

    result = le_info_init_m17n_input_methods(le_info);
    if (result == LE_FAIL) {
        le_info_destroy(le_info);
        return NULL;
    }

    return le_info;
}

Here is the call graph for this function:

Here is the caller graph for this function:

Definition at line 41 of file le_info.c.

{
#ifdef DEBUG
    if (le_info == NULL)
       return LE_FAIL;

    return LE_OK;
#endif
}

Here is the caller graph for this function:

int le_info_pushback_m17n_input_method ( LeInfoRec le_info,
M17nImInfoRec m17n_im 
)

Definition at line 52 of file le_info.c.

{
    int i, num_input_methods;

    if (le_info == NULL || m17n_im == NULL)
        return LE_FAIL;

    if (le_info->input_methods == NULL) {
        le_info->input_methods = (M17nImInfoRec **) calloc (M17N_IM_LIST_NUM_ALLOC,
                                                            sizeof(M17nImInfoRec *));
        if (le_info->input_methods == NULL)
            return LE_FAIL;
    }

    num_input_methods = le_info->num_input_methods;
    if ((num_input_methods + 1) % M17N_IM_LIST_NUM_ALLOC == 0) {
        int num = num_input_methods + 1 + M17N_IM_LIST_NUM_ALLOC;

        le_info->input_methods = (M17nImInfoRec **)realloc(le_info->input_methods,
                                                  num * sizeof(M17nImInfoRec *));
        if (le_info->input_methods == NULL)
            return LE_FAIL;

        for (i = num_input_methods; i < num; i++)
            le_info->input_methods[i] = NULL;
    }

    le_info->input_methods[num_input_methods] = m17n_im;
    le_info->num_input_methods ++;

    return LE_OK;
}

Here is the caller graph for this function:

LeResult le_info_register_ui_callbacks ( MInputMethod *  im)

Definition at line 196 of file le_info.c.

{
    MPlist *callback_list;

    if (im == (MInputMethod *)Mnil)
        return LE_FAIL;

    if (!im->driver.callback_list)
        im->driver.callback_list = (MPlist *)mplist();

    callback_list = im->driver.callback_list;

    mplist_add(callback_list, Minput_preedit_start, (void *)le_session_ui_callbacks);
    mplist_add(callback_list, Minput_preedit_draw, (void *)le_session_ui_callbacks);
    mplist_add(callback_list, Minput_preedit_done, (void *)le_session_ui_callbacks);
    mplist_add(callback_list, Minput_status_start, (void *)le_session_ui_callbacks);
    mplist_add(callback_list, Minput_status_draw, (void *)le_session_ui_callbacks);
    mplist_add(callback_list, Minput_status_done, (void *)le_session_ui_callbacks);
    mplist_add(callback_list, Minput_candidates_start, (void *)le_session_ui_callbacks);
    mplist_add(callback_list, Minput_candidates_draw, (void *)le_session_ui_callbacks);
    mplist_add(callback_list, Minput_candidates_done, (void *)le_session_ui_callbacks);

    return LE_OK;
}

Here is the call graph for this function:

Here is the caller graph for this function:

void le_session_ui_callbacks ( MInputContext *  ic,
MSymbol  command 
)

Definition at line 441 of file le_session.c.

{
    iml_session_t *s;
    LeSessionContextRec *le_session_context;

    MConverter *converter;
    UTFCHAR buf[1024];

    int layout_type_vertical = 1;
    int layout_capacity = 10;

    le_session_context = le_session_context_get_from_m17n_ic(ic);
    DEBUG_printf("le_session_ui_callbacks == le_session_context: %p\n", le_session_context);
    if (le_session_context == NULL)
        return;

    s = le_session_context->s;
    if (s == NULL)
        return;

    converter = le_info->converter;

    if (command == Minput_preedit_start) {

        DEBUG_printf("    Minput_preedit_start\n");
        le_iml_preedit_start(s);

    } else if (command == Minput_preedit_done) {

        DEBUG_printf("    Minput_preedit_done\n");
        le_iml_preedit_enddraw(s);

    } else if (command == Minput_preedit_draw) {

        int len;
        int highlight_from, highlight_to;

        DEBUG_printf("    Minput_preedit_draw, caret_pos: %d\n", ic->cursor_pos);

        if (!ic->preedit) {
            DEBUG_printf("ic->preedit is NULL, call le_iml_preedit_enddraw\n");
            le_iml_preedit_enddraw(s);
            return;
        }

        memset(buf, 0, sizeof(buf));
        mconv_rebind_buffer(converter, (unsigned char *)buf, sizeof (buf));
        mconv_encode(converter, ic->preedit);
        buf[converter->nbytes] = 0;

        len = UTFCHARLen(buf);
        if (len > 0) {

            highlight_from = 0;
            highlight_to = 0;
            if (ic->candidate_from < ic->candidate_to &&
                ic->candidate_to <= len) {
                highlight_from = ic->candidate_from;
                highlight_to = ic->candidate_to;
            }

            le_iml_preedit_draw(s, buf, ic->cursor_pos, highlight_from, highlight_to);
        } else {
            le_iml_preedit_enddraw(s);
        }

    } else if (command == Minput_status_start) {

        DEBUG_printf("    Minput_status_start\n");
        le_iml_status_start(s);

    } else if (command == Minput_status_done) {

        DEBUG_printf("    Minput_status_done\n");
        buf[0] = 0;
        le_iml_status_draw(s, buf);
        le_iml_status_enddraw(s);

    } else if (command == Minput_status_draw) {

        DEBUG_printf("    Minput_status_draw\n");

        if (!ic->status)
            return;

        memset(buf, 0, sizeof(buf));
        mconv_rebind_buffer(converter, (unsigned char *)buf, sizeof (buf));
        mconv_encode(converter, ic->status);
        buf[converter->nbytes] = 0;
        if (buf[0]) {
            le_iml_status_draw(s, buf);
        }

    } else if (command == Minput_candidates_start) {
        LayoutInfo layout;

        DEBUG_printf("    Minput_candidates_start\n");
        layout.choice_per_window = layout_capacity;
        if (layout_type_vertical) {
            layout.ncolumns = 1;
            layout.nrows = layout_capacity;
            layout.drawUpDirection = DrawUpVertically;
        } else {
            layout.ncolumns = layout_capacity;
            layout.nrows = 1;
            layout.drawUpDirection = DrawUpHorizontally;
        }
        le_iml_lookup_start(s, &layout);

    } else if (command == Minput_candidates_done) {

        DEBUG_printf("    Minput_candidates_done\n");
        le_iml_lookup_enddraw(s);

    } else if (command == Minput_candidates_draw) {

        candidates_info_t *candidates_info;

        int cur, i, len;

        MPlist *group;
        MText *mt;

        DEBUG_printf("    Minput_candidates_draw\n");
        DEBUG_printf("       candidate_index: %d\n", ic->candidate_index);
        DEBUG_printf("       candidate_from : %d\n", ic->candidate_from);
        DEBUG_printf("       candidate_to   : %d\n", ic->candidate_to);
        DEBUG_printf("       candidate_show : %d\n", ic->candidate_show);

        if (!ic->candidate_list || !ic->candidate_show) {
            le_iml_lookup_enddraw(s);
            return;
        }

        i = 0;
        group = ic->candidate_list;
        while (1) {
            if (mplist_key(group) == Mtext)
                len = mtext_len (mplist_value (group));
            else
                len = mplist_length (mplist_value (group));
            if (i + len > ic->candidate_index)
                break;
            i += len;
            group = mplist_next (group);
        }

        cur = ic->candidate_index - i;

        candidates_info = (candidates_info_t *) candidates_info_new();
        if (candidates_info == NULL)
            return;

        if (mplist_key (group) == Mtext) {
            mt = (MText *) mplist_value (group);
            memset(buf, 0, sizeof(buf));
            mconv_rebind_buffer(converter, (unsigned char *)buf, sizeof (buf));
            mconv_encode(converter, mt);
            buf[converter->nbytes] = 0;

            DEBUG_printf("converter->nbytes: %d\n", converter->nbytes);
            for (i = 0; i < UTFCHARLen(buf); i++) {
                UTFCHAR candidate[2];

                candidate[0] = buf[i];
                candidate[1] = 0;
                candidates_info_pushback_candidate(candidates_info, candidate);
            }
        } else {
            MPlist *pl;

            for (pl = (MPlist *) mplist_value (group); mplist_key (pl) != Mnil; pl = mplist_next (pl)) {
                mt = (MText *) mplist_value (pl);
                memset(buf, 0, sizeof(buf));
                mconv_rebind_buffer(converter, (unsigned char *)buf, sizeof (buf));
                mconv_encode(converter, mt);
                buf[converter->nbytes] = 0;
                DEBUG_printf("converter->nbytes: %d\n", converter->nbytes);
                if (buf[0]) {
                    candidates_info_pushback_candidate(candidates_info, buf);
                }
            }
        }

        DEBUG_printf("num_candidates: %d\n", candidates_info->num_candidates);
        if (candidates_info->num_candidates == 0) {
            candidates_info_destroy(candidates_info);
            return;
        }

        le_iml_lookup_draw(s,
                       candidates_info->num_candidates,
                       candidates_info->candidates,
                       NULL, candidates_info->labels,
                       NULL, NULL, NULL, cur,
                       layout_type_vertical ? 1 : 0);

        candidates_info_destroy(candidates_info);

        return;
    }
}

Here is the call graph for this function:

Here is the caller graph for this function:


Variable Documentation

char* disabled_langs[]
Initial value:
 {
    "zh",




}

Definition at line 331 of file le_info.c.

Definition at line 360 of file le_info.c.