Back to index

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

Go to the source code of this file.

Classes

struct  keycode_name_pair_t

Functions

char * iiim_keycode_to_name (short keycode)
MSymbol le_session_map_keyevent_to_m17n_key (IMKeyEventStruct *key_event)
void le_session_process_key_event (iml_session_t *s, IMKeyListEvent *keylistevent)

Variables

LeInfoRecle_info
static keycode_name_pair_t keycode_name_pairs []

Class Documentation

struct keycode_name_pair_t

Definition at line 148 of file le_keyevent.c.

Class Members
short keycode
char * name

Function Documentation

char * iiim_keycode_to_name ( short  keycode)

Definition at line 342 of file le_keyevent.c.

{
    int total, i;

    total = sizeof(keycode_name_pairs)/sizeof(keycode_name_pair_t);

    for (i = 0; i < total; i++) {
       if (keycode_name_pairs[i].keycode == keycode)
           return (keycode_name_pairs[i].name);
    }

    return NULL;
}

Here is the caller graph for this function:

Definition at line 81 of file le_keyevent.c.

{
    int keycode, keychar, modifier;
    char key_name[256];
    char key_string[256];

    keycode = key_event->keyCode;
    keychar = key_event->keyChar;
    modifier = key_event->modifier;

    DEBUG_printf("keycode: 0x%x, keychar:0x%x, modifier: 0x%x\n",
               keycode, keychar, modifier);

    /* Ctrl + Space */
    if ((keycode == IM_VK_SPACE) && (modifier & IM_CTRL_MASK))
       return le_info->Mkey_english_native;

    /* Ctrl + Shift */
    if (((keycode == IM_VK_CONTROL) && (modifier & IM_SHIFT_MASK)) ||
        ((keycode == IM_VK_SHIFT) && (modifier & IM_CTRL_MASK)))
       return le_info->Mkey_switch_next_im;

    memset(key_name, 0, sizeof(key_name));

    /* Normal Alphameric key */
    if (keychar >= 0x20 && keychar <= 0x7e) {

            if ((modifier & IM_CTRL_MASK) &&
                (keychar  >= 'a' && keychar <= 'z'))
                keychar += 'A' - 'a';
           key_name[0] = keychar;

    } else if (keychar == 0) {
        char *key_str;

        if (keycode == IM_VK_SHIFT ||
            keycode == IM_VK_CONTROL ||
            keycode == IM_VK_ALT ||
            keycode == IM_VK_CAPS_LOCK)
            return Mnil;

        key_str = iiim_keycode_to_name(keycode);
        DEBUG_printf("iiim_keycode_to_name: key_str: %s\n", key_str? key_str: "NULL");
        if (! key_str)
            return Mnil;

        strncpy(key_name, key_str, sizeof(key_name));
    }

    if (!*key_name)
        return Mnil;

    memset(key_string, 0, sizeof(key_string));

    if (modifier & IM_SHIFT_MASK)
       strncat(key_string, "S-", sizeof(key_string));
    if (modifier & IM_CTRL_MASK)
       strncat(key_string, "C-", sizeof(key_string));
    if (modifier & IM_META_MASK)
       strncat(key_string, "M-", sizeof(key_string));
    if (modifier & IM_ALT_MASK)
       strncat(key_string, "A-", sizeof(key_string));

    strncat(key_string, key_name, sizeof(key_string));
    return msymbol(key_string);
}

Here is the call graph for this function:

Here is the caller graph for this function:

void le_session_process_key_event ( iml_session_t s,
IMKeyListEvent keylistevent 
)

Definition at line 11 of file le_keyevent.c.

{
    LeSessionContextRec *le_session_context;

    MInputContext *ic;
    MSymbol m17n_key;
    MConverter *converter;
    MText *produced;

    int ret;
    UTFCHAR buf[256];

    IMKeyEventStruct *key_event =
       (IMKeyEventStruct *) keylistevent->keylist;

    le_session_context =
       (LeSessionContextRec *) le_session_get_session_context(s);
    m17n_key = le_session_map_keyevent_to_m17n_key(key_event);

    if (le_session_context == NULL ||
       le_session_context->ic == (MInputContext *) Mnil
       || m17n_key == Mnil) {
       le_iml_sendback_key(s, key_event);
       return;
    }

    DEBUG_printf("m17n_key: %s\n", msymbol_name(m17n_key));
    if (m17n_key == le_info->Mkey_switch_next_im) {
        le_session_switch_to_next_input_method(s);
        return;
    }

    if (m17n_key == le_info->Mkey_english_native) {
       le_session_set_conversion_status(s, CONVERSION_OFF);
       return;
    }

    ic = le_session_context->ic;
    ret = minput_filter(ic, m17n_key, NULL);
    if (ret) {
       DEBUG_printf("minput_filter return 1\n");
       return;
    }

    produced = mtext();

    ret = minput_lookup(ic, m17n_key, NULL, produced);
    if (mtext_len(produced) <= 0) {
       DEBUG_printf("minput_lookup return -1\n");
       le_iml_sendback_key(s, key_event);
       return;
    }

    converter = le_info->converter;

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

    if (buf[0]) {
       DEBUG_printf("commit buf: 0x%x\n", buf[0]);
       le_iml_commit(s, buf);
    }

    return;
}

Here is the call graph for this function:

Here is the caller graph for this function:


Variable Documentation

Definition at line 153 of file le_keyevent.c.

Definition at line 39 of file le_interface.c.