Back to index

im-sdk  12.3.91
Functions
codepoint_filter.h File Reference
#include "unit_input.h"
This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Functions

int codepoint_filter (TableStruct *unit_table, IMEKey key_event, IMEBufferRec *ime_buffer)
int map_keyevent_to_imekey (TableStruct *unit_table, IMEKey key_event)
int convert_UCS4_to_UTF8 (unsigned int *, unsigned char *)

Function Documentation

int codepoint_filter ( TableStruct unit_table,
IMEKey  key_event,
IMEBufferRec ime_buffer 
)

Definition at line 151 of file codepoint_filter.c.

{
  int     key, default_input_len;
 
  ime_buffer->encode = unit_table->Encode;
  default_input_len = unit_table->Default_Input;

  IME_Status = 0;

  key = map_keyevent_to_imekey(unit_table, key_event);
  log_f("codepoint_filter: map_keyevent_to_imekey: return key:0x%x\n", key);
 
  if (key == IME_NOT_USED_KEY){
    log_f("IME_NOT_USED_KEY \n");
    return(IME_NOT_USED_KEY);
  }

  if (esc_key_flag)
    default_input_len = unit_table->Max_Input; 

  if (Is_UsedCodes_Key(unit_table, key)){
    /* if not key by key, and is selectkey, and Lookup Mode */
    /* directly select */
  
    Input_Buf[Input_Len] = key;
    Input_Len ++;
    Input_Buf[Input_Len] = 0;
  
    log_f("Input_Len:%d\n",Input_Len);

    if (Input_Len == default_input_len){
      Preedit_Buf[Preedit_Len] = key;
      Preedit_Len += 1;
      Preedit_Buf[Preedit_Len] = '\0';
      if (commit_candidate(ime_buffer, unit_table) == RETURN_KEY) {
        Preedit_Len = 0;
        Preedit_CaretPos = 0;
        Input_Len = 0;
        Input_Buf[Input_Len]='\0';
        IME_Status |= IME_PREEDIT_AREA; 
        return RETURN_KEY;
      }
      Preedit_Len = 0;
      Preedit_CaretPos = 0;
      Input_Len = 0;
      Input_Buf[Input_Len]='\0';
      IME_Status |= IME_PREEDIT_AREA; 
      return(IME_USED_KEY);
    }

    Preedit_Buf[Preedit_Len] = key;
    Preedit_Len += 1;
    Preedit_Buf[Preedit_Len] = '\0';
    Preedit_CaretPos = Preedit_Len;
    IME_Status = IME_PREEDIT_AREA;
    return(IME_USED_KEY);
  }

  if (Is_ClearAll_Key(unit_table, key)) { 
    /* Esc , clear preedit and so on */
    log_f("ESC_KEY\n");
    if (!esc_key_flag)
      esc_key_flag = 1;
    else
      esc_key_flag = 0;

    return(IME_NOT_USED_KEY);
  }

  if (Is_BackSpace_Key(unit_table, key)) { /* Back Space & Delete */
    log_f("BACKSPACE_KEY, Input_Len:%d, Preedit_Len:%d\n", Input_Len, Preedit_Len);
    /*  if no inputted key, directly return this key */
    if (Input_Len==0) {
      return(IME_NOT_USED_KEY);
    }

    Input_Len --;
    Input_Buf[Input_Len] = '\0';
    Preedit_Len -= 1;
    Preedit_Buf[Preedit_Len] = '\0';
    Preedit_CaretPos = Preedit_Len;
    IME_Status = IME_PREEDIT_AREA;

    return(IME_USED_KEY);
  }

  if (Is_Commit_Key(unit_table, key)) { /* space or return key */
    log_f("SPACE/RETURN KEY\n");
    if (Input_Len==0){
      return(IME_NOT_USED_KEY);
    }

    /* if any keys and key is Space key and mode is not keybykey */
    /* then search and display the candidates */

    if (Preedit_Len > 0){
      log_f("RETURN/SPACE key: Input_Buf:%s\n",Input_Buf);
      log_f("RETURN/SPACE key: Preedit_Buf:%s\n",Preedit_Buf);
      commit_candidate(ime_buffer, unit_table);
    }
    /* clear Preedit_Buf and Input_Buf */ 
    Preedit_Len = 0;
    Preedit_CaretPos = 0;
    Input_Len = 0;
    Input_Buf[Input_Len]='\0';
    IME_Status |= IME_PREEDIT_AREA; 
    return(IME_USED_KEY);
  }

  /* for unnormal keys 
     if (Input_Len==0) return(IME_NOT_USED_KEY);
     else return(IME_USED_KEY);
  */
  return(IME_USED_KEY);
}

Here is the call graph for this function:

Here is the caller graph for this function:

int convert_UCS4_to_UTF8 ( unsigned int *  ,
unsigned char *   
)

Definition at line 335 of file codepoint_filter.c.

                                                                         {
  int to_len = 0;
  unsigned char *ptr = to_buf;
                                                                                              
  if ( *from_buf <= 0x7F) {
    *ptr++ = (unsigned char) *from_buf;
    to_len++;
    from_buf++;
  } else if ( *from_buf <= 0x07FF ) {
    *ptr++= (unsigned char) ((*from_buf >> 6) | 0xC0 );
    *ptr++= (unsigned char) ((*from_buf & 0x3F) | 0x80 );
    to_len+=2;
    from_buf++;
  } else if ( *from_buf <= 0xFFFF ) {
    *ptr++= (unsigned char) ((*from_buf >> 12) | 0xE0 );
    *ptr++= (unsigned char) ((*from_buf >> 6 & 0x3F) | 0x80 );
    *ptr++= (unsigned char) ((*from_buf & 0x3F) | 0x80 );
    to_len+=3;
    from_buf++;
  } else if ( *from_buf <= 0x1FFFFF ) {
    *ptr++= (unsigned char) ((*from_buf >> 18) | 0xF0 );
    *ptr++= (unsigned char) (((*from_buf >> 12) & 0x3F) | 0x80 );
    *ptr++= (unsigned char) ((*from_buf >> 6 & 0x3F) | 0x80 );
    *ptr++= (unsigned char) ((*from_buf & 0x3F)| 0x80 );
    to_len+=4;
    from_buf++;
  }
  log_f("to_len [%d]\n",to_len);
  return (to_len);
}

Here is the call graph for this function:

Here is the caller graph for this function:

int map_keyevent_to_imekey ( TableStruct unit_table,
IMEKey  key_event 
)

Definition at line 273 of file codepoint_filter.c.

{
  int keycode, keystatus, keychar;

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

  log_f("codepoint_filter: keycode: 0x%x, keychar:0x%x, keystatus: 0x%x\n", keycode, keychar, keystatus);
  /* normal status */
  if (keystatus  == 0) {
    /* Function Keys */
    if (keychar == 0) {
      log_f(" Function Key :%d\n", keycode);
      switch (keycode) {
      case IM_VK_ESCAPE:
       return(ESC_KEY);

      case IM_VK_BACK_SPACE:
       return(BACKSPACE_KEY);

      case IM_VK_ENTER:
       return(RETURN_KEY);

      case IM_VK_INSERT:
       return(INSERT_KEY);

      case IM_VK_DELETE:
       return(DELETE_KEY);

      case IM_VK_HOME:
       return(HOME_KEY);

      case IM_VK_END:
       return(END_KEY);

      case IM_VK_PAGE_UP:
       return(PAGEUP_KEY);

      case IM_VK_PAGE_DOWN:
       return(PAGEDOWN_KEY);

      }
      return(IME_NOT_USED_KEY);
    } else {
      /*  normal key  */
      log_f("codepoint_filter:  Normal Key :0x%x, %c\n", keychar, keychar);
      return(keychar);
    }
  }

  /*  Shift status */
  if (keystatus == IM_SHIFT_MASK) {
    if (keychar != 0) {
      /*  normal key  */
      log_f("codepoint_filter:  Ascii Key :0x%x, %c\n", keychar, keychar);
      return(keychar);
    }
  }
  return (IME_NOT_USED_KEY);
}