Ejemplo n.º 1
0
static void load_seg()
{
      clear_seg_label();
      struct anthy_conv_stat acs;
      anthy_get_stat(ac, &acs);
      segN = 0;
      if (acs.nr_segment > 0) {
        char buf[256];
        int i;

        for(i=0; i < acs.nr_segment; i++) {
          anthy_get_segment(ac, i, 0, buf, sizeof(buf));

          seg[i].selidx = 0;
          gtk_label_set_text(GTK_LABEL(seg[i].label), buf);

          struct anthy_segment_stat ss;
          anthy_get_segment_stat(ac, i, &ss);

          seg[i].selN = ss.nr_candidate;
          segN++;
        }

        state=STATE_CONVERT;
//        cursor = 0;
        if (cursor >= acs.nr_segment)
          cursor = acs.nr_segment - 1;
        disp_convert();
      }
      keysN=0;
}
Ejemplo n.º 2
0
static void load_seg()
{
    dbg("load_seg sel_segN:%d\n", sel_segN);
    clear_seg_label();
    struct anthy_conv_stat acs;
    anthy_get_stat(ac, &acs);
    segN = 0;
    if (acs.nr_segment > 0) {
        char buf[256];
        int i;

        int ofs = 0;
        for(i=0; i < acs.nr_segment; i++) {
          struct anthy_segment_stat ss;
          anthy_get_segment_stat(ac, i, &ss);
          int len = ss.seg_len;
          int idx = get_sel_seg_with_ofs(ofs);
          dbg("%d] sel idx:%d ofs:%d\n",i, idx, ofs);
          int selN = seg[i].selN = ss.nr_candidate;

          char *old_str = NULL;
          seg[i].selidx = 0;
          if (idx < sel_segN && sel_seg[idx].len==len) {
            int j;
            for(j=0;j<selN;j++) {
                anthy_get_segment(ac, i, j, buf, sizeof(buf));
                if (!strcmp(buf, sel_seg[idx].sel_str) ) {
                  dbg("old found %s", buf);
                  seg[i].selidx = j;
                  break;
              }
            }
          }

          anthy_get_segment(ac, i, seg[i].selidx, buf, sizeof(buf));
          gtk_label_set_text(GTK_LABEL(seg[i].label), buf);

          dbg("seg len:%d\n", len);
          seg[i].ofs = ofs;
          seg[i].len = len;
          segN++;
          ofs += len;
        }

        state=STATE_CONVERT;
//        cursor = 0;
        if (cursor >= acs.nr_segment)
          cursor = acs.nr_segment - 1;
        disp_convert();
      }
      keysN=0;
}
Ejemplo n.º 3
0
gboolean module_feedkey(int kv, int kvstate)
{
  int lkv = tolower(kv);
  int shift_m=(kvstate&ShiftMask) > 0;
//  printf("%x %c  %d\n", kv, kv, shift_m);

  if (kvstate & ControlMask)
    return FALSE;
  if (kvstate & (Mod1Mask|Mod4Mask|Mod5Mask))
    return FALSE;

  if (kv==XK_Shift_L||kv==XK_Shift_R) {
    key_press_time = gmf.mf_current_time();
  }

  if (!gmf.mf_tsin_pho_mode())
    return 0;

  gboolean b_is_empty = is_empty();

  switch (kv) {
    case XK_F7:
      if (is_empty())
        return FALSE;
      state = STATE_ROMANJI;
      if (state_hira_kata != STATE_kata)
        state_hira_kata = STATE_kata;
      else
        state_hira_kata = STATE_hira;
      disp_input();
      return TRUE;
    case XK_F8:
      if (is_empty())
        return FALSE;
      state = STATE_ROMANJI;
      if (state_hira_kata != STATE_half_kata)
        state_hira_kata = STATE_half_kata;
      else
        state_hira_kata = STATE_hira;
      disp_input();
      return TRUE;
    case XK_F11:
      system("kasumi &");
      return TRUE;
    case XK_F12:
      system("kasumi -a &");
      return TRUE;
    case XK_Up:
      if (b_is_empty)
        return FALSE;
      if (state==STATE_SELECT) {
        int N = page_N();
        gmf.mf_tss->pho_menu_idx--;
        if (gmf.mf_tss->pho_menu_idx < 0)
          gmf.mf_tss->pho_menu_idx = N - 1;
        disp_select();
      }
      return TRUE;
    case XK_Down:
      if (b_is_empty)
        return FALSE;
      if (state==STATE_CONVERT) {
        state = STATE_SELECT;
        gmf.mf_tss->sel_pho = TRUE;
  //      puts("STATE_SELECT");
        disp_select();
      } else
      if (state==STATE_SELECT) {
        int N = page_N();
        gmf.mf_tss->pho_menu_idx=(gmf.mf_tss->pho_menu_idx+1)% N;
        disp_select();
      }
      return TRUE;
    case XK_Return:
      if (b_is_empty)
        return FALSE;
      if (state==STATE_SELECT) {
        if (select_idx(gmf.mf_tss->pho_menu_idx))
          goto send;
        return TRUE;
      }
send:
      return module_flush_input();
    case XK_Escape:
        if (state==STATE_SELECT) {
          state = STATE_CONVERT;
          gmf.mf_tss->sel_pho = FALSE;
          gmf.mf_clear_sele();
        }
        else
        if (state==STATE_CONVERT)
          goto rom;
      return FALSE;
    case XK_BackSpace:
      if (b_is_empty) {
        state_hira_kata = STATE_hira;
        return FALSE;
      }

      gmf.mf_hide_selections_win();

      if (state&(STATE_CONVERT|STATE_SELECT)) {
rom:
//        puts("romanji");
        state = STATE_ROMANJI;
        cursor = jpN;
        segN = 0;
        disp_input();
        return TRUE;
      }

//      puts("back");
      if (keysN) {
        keysN--;
        keys[keysN]=0;
      }
      else
      if (jpN && cursor) {
        delete_jpstr(cursor-1);
        cursor--;
      } else
        return FALSE;
      disp_input();
      auto_hide();
      return TRUE;
    case XK_Delete:
      if (b_is_empty)
        return FALSE;
      if (state&STATE_ROMANJI) {
        if (keysN)
          return TRUE;
        delete_jpstr(cursor);
        disp_input();
      }
      auto_hide();
      return TRUE;
    case XK_Left:
      if (b_is_empty)
        return FALSE;
      if (state&STATE_ROMANJI) {
        if (keysN)
          keysN = 0;
        else {
          if (cursor)
            cursor--;
        }
        disp_input();
      } else
      if (state&STATE_CONVERT) {
        if (shift_m) {
          anthy_resize_segment(ac, cursor, -1);
          load_seg();
        } else {
          if (cursor)
            cursor--;
        }
        disp_convert();
      }
      return TRUE;
    case XK_Right:
      if (b_is_empty)
        return FALSE;
      if (state&STATE_ROMANJI) {
        if (cursor < jpN)
          cursor++;
        disp_input();
      } else
      if (state&STATE_CONVERT) {
        if (shift_m) {
          anthy_resize_segment(ac, cursor, 1);
          load_seg();
        } else {
          if (cursor < segN-1)
            cursor++;
        }
        disp_convert();
      }
      return TRUE;
    case XK_Home:
      if (b_is_empty)
        return FALSE;
      cursor = 0;
      if (state&STATE_ROMANJI) {
        disp_input();
      } else
      if (state&STATE_CONVERT) {
        disp_convert();
      }
      return TRUE;
    case XK_End:
      if (b_is_empty)
        return FALSE;
      if (state&STATE_ROMANJI) {
        cursor = jpN;
        disp_input();
      } else
      if (state&STATE_CONVERT) {
        cursor = segN-1;
        disp_convert();
      }
      return TRUE;
    case XK_Prior:
      if (state!=STATE_SELECT)
        return FALSE;
      prev_page();
      return TRUE;
    case XK_Next:
      if (state!=STATE_SELECT)
        return FALSE;
      next_page();
      return TRUE;
    case ' ':
      if (b_is_empty)
        return FALSE;
      goto lab1;
    default:
      if (state==STATE_SELECT) {
        char *pp;
        if ((pp=strchr(*gmf.mf_pho_selkey, lkv))) {
          int c=pp-*gmf.mf_pho_selkey;
          if (select_idx(c))
            goto send;
        }
        return TRUE;
      }
  }

//  printf("kv %d\n", kv);
  if (!is_legal_char(kv))
    return FALSE;

  kv = lkv;

  if (state==STATE_CONVERT && kv!=' ') {
    send_seg();
    state = STATE_ROMANJI;
  }

lab1:
  if (state==STATE_ROMANJI) {
    if (keysN < MAX_KEYS)
      keys[keysN++]=kv;

    keys[keysN]=0;
    parse_key();
    disp_input();
  }

  module_show_win();

  if (kv==' ') {
    if (state==STATE_ROMANJI) {
      char tt[512];
      clear_seg_label();
      merge_jp(tt, TRUE);
//      dbg("tt %s %d\n", tt, strlen(tt));
      anthy_set_string(ac, tt);
      load_seg();
    } else
    if (state==STATE_CONVERT) {
      state = STATE_SELECT;
      gmf.mf_tss->sel_pho = TRUE;
//      puts("STATE_SELECT");
      disp_select();
    } else
    if (state==STATE_SELECT) {
      next_page();
    }
  }

  return TRUE;
}