void module_hide_win (void) { gtk_widget_hide (g_pWinChewing); g_gcinModMainFuncs.mf_hide_selections_win (); g_gcinModMainFuncs.mf_hide_win_sym (); }
// FIXME: the pos of g_pSeg[].label is not correct static gboolean gcin_label_cand_show (char *pszWord, int nIdx) { int nX, nY; int nFontWidth, nFontHeight; g_gcinModMainFuncs.mf_set_sele_text (nIdx, pszWord, -1); // find the position of the cand win g_gcinModMainFuncs.mf_get_widget_xy (g_pWinChewing, g_pSeg[g_nCurrentCursorPos].label, &nX, &nY); gtk_pango_font_pixel_size_get (&nFontWidth, &nFontHeight); nX += g_nCurrentCursorPos * nFontWidth; nY = g_gcinModMainFuncs.mf_gcin_edit_display_ap_only () ? *g_gcinModMainFuncs.mf_win_y : *g_gcinModMainFuncs.mf_win_y + *g_gcinModMainFuncs.mf_win_yl; g_gcinModMainFuncs.mf_disp_selections (nX, nY); return TRUE; }
int module_feedkey_release(KeySym xkey, int kbstate) { switch (xkey) { case XK_Shift_L: case XK_Shift_R: if ( ( (*gmf.mf_tsin_chinese_english_toggle_key == TSIN_CHINESE_ENGLISH_TOGGLE_KEY_Shift) || (*gmf.mf_tsin_chinese_english_toggle_key == TSIN_CHINESE_ENGLISH_TOGGLE_KEY_ShiftL && xkey == XK_Shift_L) || (*gmf.mf_tsin_chinese_english_toggle_key == TSIN_CHINESE_ENGLISH_TOGGLE_KEY_ShiftR && xkey == XK_Shift_R)) && gmf.mf_current_time() - key_press_time < 300000) { #if WIN32 if (!*gmf.test_mode) #endif { module_flush_input(); key_press_time = 0; gmf.mf_hide_selections_win(); gmf.mf_tsin_set_eng_ch(!gmf.mf_tsin_pho_mode()); } return 1; } else return 0; default: return 0; } }
void module_change_font_size() { dbg("change_anthy_font_size\n"); GdkColor fg; gdk_color_parse(*gmf.mf_gcin_win_color_fg, &fg); #if GTK_CHECK_VERSION(2,91,6) GdkRGBA rgbfg; gdk_rgba_parse(&rgbfg, gdk_color_to_string(&fg)); #endif gmf.mf_change_win_bg(win_anthy); gmf.mf_change_win_bg(event_box_anthy); int i; for(i=0; i < MAX_SEG_N; i++) { GtkWidget *label = seg[i].label; gmf.mf_set_label_font_size(label, *gmf.mf_gcin_font_size); if (*gmf.mf_gcin_win_color_use) { #if !GTK_CHECK_VERSION(2,91,6) gtk_widget_modify_fg(label, GTK_STATE_NORMAL, &fg); #else gtk_widget_override_color(label, GTK_STATE_FLAG_NORMAL, &rgbfg); #endif } } }
void module_change_font_size (void) { GdkColor colorFG; GtkWidget *pLabel; int n; gdk_color_parse (*g_gcinModMainFuncs.mf_gcin_win_color_fg, &colorFG); g_gcinModMainFuncs.mf_change_win_bg (g_pWinChewing); g_gcinModMainFuncs.mf_change_win_bg (g_pEvBoxChewing); for (n = 0; n < MAX_SEG_NUM; n++) { pLabel = g_pSeg[n].label; g_gcinModMainFuncs.mf_set_label_font_size (pLabel, *g_gcinModMainFuncs.mf_gcin_font_size); if (*g_gcinModMainFuncs.mf_gcin_win_color_use) { #if !GTK_CHECK_VERSION(2,91,6) gtk_widget_modify_fg (pLabel, GTK_STATE_NORMAL, &colorFG); #else GdkRGBA rgbfg; gdk_rgba_parse(&rgbfg, gdk_color_to_string(&colorFG)); gtk_widget_override_color(pLabel, GTK_STATE_FLAG_NORMAL, &rgbfg); #endif } } }
void module_hide_win() { if (state == STATE_SELECT) { state = STATE_CONVERT; gmf.mf_hide_selections_win(); } gtk_widget_hide(win_anthy); gmf.mf_hide_win_sym(); }
void module_show_win() { if (gmf.mf_gcin_edit_display_ap_only()) return; if (!*gmf.mf_gcin_pop_up_win || !is_empty() || *gmf.mf_force_show ) { if (!module_win_visible()) gtk_widget_show(win_anthy); gmf.mf_show_win_sym(); } }
static void mouse_button_callback( GtkWidget *widget,GdkEventButton *event, gpointer data) { // dbg("mouse_button_callback %d\n", event->button); switch (event->button) { case 1: gmf.mf_toggle_win_sym(); break; case 2: gmf.mf_inmd_switch_popup_handler(widget, (GdkEvent *)event); break; case 3: gmf.mf_exec_gcin_setup(); break; } }
void module_show_win (void) { if (g_gcinModMainFuncs.mf_gcin_edit_display_ap_only ()) return; if (is_empty ()) return; gtk_window_resize (GTK_WINDOW (g_pWinChewing), 32 * (chewing_buffer_Check (g_pChewingCtx) + 1), 12); gtk_widget_show (g_pWinChewing); g_gcinModMainFuncs.mf_show_win_sym (); }
static void disp_input() { int i; if (gmf.mf_gcin_edit_display_ap_only()) return; clear_seg_label(); int idx; for(idx=i=0; i < jpN; i++) { if (i==cursor) { disp_keys(idx); idx+=keysN; cursor_markup(idx++, idx_hira_kata(jp[i], FALSE)); } else gtk_label_set_text(GTK_LABEL(seg[idx++].label), idx_hira_kata(jp[i], FALSE)); } if (cursor==jpN) { disp_keys(idx); idx+=keysN; cursor_markup(idx, " "); } minimize_win_anthy(); }
void module_win_geom() { if (!win_anthy) return; gtk_window_get_position(GTK_WINDOW(win_anthy), gmf.mf_win_x, gmf.mf_win_y); gmf.mf_get_win_size(win_anthy, gmf.mf_win_xl, gmf.mf_win_yl); }
void module_win_geom() { if (!gwin_int) return; gtk_window_get_position(GTK_WINDOW(gwin_int), gmf.mf_win_x, gmf.mf_win_y); gmf.mf_get_win_size(gwin_int, gmf.mf_win_xl, gmf.mf_win_yl); }
static void disp_select() { // puts("disp_select"); gmf.mf_clear_sele(); int endn = pageidx + gmf.mf_phkbm->selkeyN; if (endn > seg[cursor].selN) endn = seg[cursor].selN; int i; for(i=pageidx; i<endn; i++) { char buf[256]; anthy_get_segment(ac, cursor, i, buf, sizeof(buf)); // printf("%d %s\n", i, buf); gmf.mf_set_sele_text(seg[cursor].selN, i - pageidx, buf, -1); } if (pageidx) gmf.mf_disp_arrow_up(); if (i < seg[cursor].selN) gmf.mf_disp_arrow_down(); int x,y; gmf.mf_get_widget_xy(win_anthy, seg[cursor].label, &x, &y); // printf("%x cusor %d %d\n", win_anthy, cursor, x); y = gmf.mf_gcin_edit_display_ap_only()? *gmf.mf_win_y:*gmf.mf_win_y+*gmf.mf_win_yl; gmf.mf_disp_selections(x, y); }
void module_win_geom (void) { if (!g_pWinChewing) return; gtk_window_get_position(GTK_WINDOW(g_pWinChewing), g_gcinModMainFuncs.mf_win_x, g_gcinModMainFuncs.mf_win_y); g_gcinModMainFuncs.mf_get_win_size(g_pWinChewing, g_gcinModMainFuncs.mf_win_xl, g_gcinModMainFuncs.mf_win_yl); }
static void send_seg() { char out[512]; int i; for(i=0, out[0]=0; i < segN; i++) { strcat(out, gtk_label_get_text(GTK_LABEL(seg[i].label))); anthy_commit_segment(ac, i, seg[i].selidx); seg[i].selidx = 0; } // printf("sent convert '%s'\n", out); gmf.mf_send_text(out); clear_all(); }
int module_flush_input (void) { char *pszTmp; if (chewing_commit_Check (g_pChewingCtx)) { pszTmp = chewing_commit_String (g_pChewingCtx); g_gcinModMainFuncs.mf_send_text (pszTmp); free (pszTmp); } chewing_Reset (g_pChewingCtx); return 0; }
int module_flush_input() { gmf.mf_hide_selections_win(); int val; if (state==STATE_CONVERT) { val = TRUE; send_seg(); } else { val = send_jp(); } // dbg("cursor %d\n", cursor); clear_all(); return val; }
static gboolean select_idx(int c) { int idx = pageidx + c; if (idx < seg[cursor].selN) { char buf[256]; anthy_get_segment(ac, cursor, idx, buf, sizeof(buf)); gtk_label_set_text(GTK_LABEL(seg[cursor].label), buf); seg[cursor].selidx = idx; state = STATE_CONVERT; gmf.mf_hide_selections_win(); return (segN==1); } return FALSE; }
static gboolean send_jp() { char out[512]; merge_jp(out, FALSE); if (!out[0]) return FALSE; clear_seg_label(); jpN=0; keysN = 0; // printf("sent romanji '%s'\n", out); gmf.mf_send_text(out); segN = 0; return TRUE; }
// FIXME: refine and chk int module_get_preedit (char *pszStr, GCIN_PREEDIT_ATTR gcinPreeditAttr[], int *pnCursor, int *pCompFlag) { char *pszTmpStr = NULL; int nIdx; int nLength; int nTotalLen = 0; int nAttr = 0; pszStr[0] = 0; *pnCursor = 0; gcinPreeditAttr[0].flag = GCIN_PREEDIT_ATTR_FLAG_UNDERLINE; gcinPreeditAttr[0].ofs0 = 0; if (chewing_buffer_Len (g_pChewingCtx)) nAttr = 1; for (nIdx = 0; nIdx < chewing_buffer_Len (g_pChewingCtx); nIdx++) { pszTmpStr = (char *)gtk_label_get_text (GTK_LABEL (g_pSeg[nIdx].label)); nLength = g_gcinModMainFuncs.mf_utf8_str_N (pszTmpStr); nTotalLen += nLength; if (nIdx < chewing_cursor_Current (g_pChewingCtx)) *pnCursor += nLength; #if 0 if (nIdx == chewing_cursor_Current (g_pChewingCtx)) { gcinPreeditAttr[1].ofs0 = *pnCursor; gcinPreeditAttr[1].ofs1 = *pnCursor + nLength; gcinPreeditAttr[1].flag = GCIN_PREEDIT_ATTR_FLAG_REVERSE; nAttr++; } #endif strcat (pszStr, pszTmpStr); } gcinPreeditAttr[0].ofs1 = nTotalLen; pCompFlag = 0; return nAttr; }
void module_move_win(int x, int y) { #if 0 best_win_x = x; best_win_y = y; #endif gtk_window_get_size(GTK_WINDOW(win_anthy), gmf.mf_win_xl, gmf.mf_win_yl); if (x + *gmf.mf_win_xl > *gmf.mf_dpy_xl) x = *gmf.mf_dpy_xl - *gmf.mf_win_xl; if (x < 0) x = 0; if (y + *gmf.mf_win_yl > *gmf.mf_dpy_yl) y = *gmf.mf_dpy_yl - *gmf.mf_win_yl; if (y < 0) y = 0; gtk_window_move(GTK_WINDOW(win_anthy), x, y); *gmf.mf_win_x = x; *gmf.mf_win_y = y; gmf.mf_move_win_sym(); }
void module_move_win (int nX, int nY) { gtk_window_get_size (GTK_WINDOW (g_pWinChewing), g_gcinModMainFuncs.mf_win_xl, g_gcinModMainFuncs.mf_win_yl); if (nX + *g_gcinModMainFuncs.mf_win_xl > *g_gcinModMainFuncs.mf_dpy_xl) nX = *g_gcinModMainFuncs.mf_dpy_xl - *g_gcinModMainFuncs.mf_win_xl; if (nX < 0) nX = 0; if (nY + *g_gcinModMainFuncs.mf_win_yl > *g_gcinModMainFuncs.mf_dpy_yl) nY = *g_gcinModMainFuncs.mf_dpy_yl - *g_gcinModMainFuncs.mf_win_yl; if (nY < 0) nY = 0; gtk_window_move (GTK_WINDOW(g_pWinChewing), nX, nY); *g_gcinModMainFuncs.mf_win_x = nX; *g_gcinModMainFuncs.mf_win_y = nY; g_gcinModMainFuncs.mf_move_win_sym (); }
void create_win_intcode() { if (gwin_int) { module_show_win(); return; } gwin_int = gtk_window_new (GTK_WINDOW_TOPLEVEL); gtk_window_set_has_resize_grip(GTK_WINDOW(gwin_int), FALSE); gtk_window_set_resizable(GTK_WINDOW(gwin_int), FALSE); #if WIN32 gmf.mf_set_no_focus(gwin_int); #endif // gtk_window_set_default_size(GTK_WINDOW (gwin_int), 1, 1); gtk_container_set_border_width (GTK_CONTAINER (gwin_int), 0); GdkWindow *gdkwin = gtk_widget_get_window(gwin_int); GtkWidget *frame = gtk_frame_new(NULL); gtk_container_set_border_width (GTK_CONTAINER (frame), 0); gtk_container_add (GTK_CONTAINER(gwin_int), frame); GtkWidget *hbox_top = gtk_hbox_new (FALSE, 0); gtk_container_add (GTK_CONTAINER (frame), hbox_top); GtkWidget *button_intcode = gtk_button_new_with_label(_(_L("內碼"))); g_signal_connect (G_OBJECT (button_intcode), "button_press_event", G_CALLBACK (gmf.mf_inmd_switch_popup_handler), NULL); gtk_box_pack_start (GTK_BOX (hbox_top), button_intcode, FALSE, FALSE, 0); button_int = gtk_button_new(); gtk_container_set_border_width (GTK_CONTAINER (button_int), 0); gtk_box_pack_start (GTK_BOX (hbox_top), button_int, FALSE, FALSE, 0); GtkWidget *hbox_int = gtk_hbox_new (FALSE, 0); gtk_container_add (GTK_CONTAINER (button_int), hbox_int); int i; for(i=0; i < MAX_INTCODE;i ++) { GtkWidget *label = gtk_label_new(_(full_space)); labels_int[i] = label; gtk_box_pack_start (GTK_BOX (hbox_int), label, FALSE, FALSE, 0); gmf.mf_set_label_font_size(label, *gmf.mf_gcin_font_size); } GtkWidget *intsel = create_int_opts(); gtk_box_pack_start (GTK_BOX (hbox_top), intsel, FALSE, FALSE, 0); gtk_widget_show_all (gwin_int); gtk_widget_realize (gwin_int); #if WIN32 gmf.mf_win32_init_win(gwin_int); #else set_no_focus(gwin_int); #endif adj_intcode_buttons(); minimize_win(); // dbg("create %x\n",gwin_int); }
int module_get_preedit(char *str, GCIN_PREEDIT_ATTR attr[], int *pcursor, int *comp_flag) { int i; // dbg("anthy_get_preedit %d\n", cursor); str[0]=0; *pcursor=0; attr[0].flag=GCIN_PREEDIT_ATTR_FLAG_UNDERLINE; attr[0].ofs0=0; int attrN=0; int ch_N=0; if (state==STATE_CONVERT) { if (segN) attrN=1; for(i=0; i < segN; i++) { char *s = (char *)gtk_label_get_text(GTK_LABEL(seg[i].label)); int N = gmf.mf_utf8_str_N(s); ch_N+=N; if (i < cursor) *pcursor+=N; if (gmf.mf_gcin_edit_display_ap_only() && i==cursor) { attr[1].ofs0=*pcursor; attr[1].ofs1=*pcursor+N; attr[1].flag=GCIN_PREEDIT_ATTR_FLAG_REVERSE; attrN++; } strcat(str, s); } attr[0].ofs1 = ch_N; } else { if (jpN) attrN=1; keys[keysN]=0; for(i=0;i < jpN; i++) { char *s=idx_hira_kata(jp[i], FALSE); int N = gmf.mf_utf8_str_N(s); // dbg("%d]%s N:%d\n", i, s, N); if (gmf.mf_gcin_edit_display_ap_only() && i==cursor) { strcat(str, keys); ch_N+=keysN; *pcursor = ch_N; attr[1].ofs0=ch_N; attr[1].ofs1=ch_N+N; attr[1].flag=GCIN_PREEDIT_ATTR_FLAG_REVERSE; attrN++; } strcat(str, s); ch_N+=N; } if (cursor==jpN) { *pcursor = ch_N; strcat(str, keys); ch_N+=keysN; } attr[0].ofs1 = ch_N; // dbg("cursor %d ch_N:%d '%s'\n", *pcursor, ch_N, str); } *comp_flag = keysN>0; if (win_anthy && GTK_WIDGET_VISIBLE(win_anthy)) *comp_flag|=2; if (segN || jpN) *comp_flag|=4; return attrN; }
gboolean module_feedkey (int nKeyVal, int nKeyState) { char *pszTmp = NULL; char *pszChewingCand = NULL; int nZuinLen = 0; char szWord[4]; int nPhoIdx, nBufIdx; int nIdx; if (!g_pChewingCtx) return FALSE; memset (szWord, 0x00, 4); if (!g_gcinModMainFuncs.mf_tsin_pho_mode ()) return FALSE; switch (nKeyVal) { case XK_space: chewing_handle_Space (g_pChewingCtx); break; case XK_Escape: chewing_handle_Esc (g_pChewingCtx); break; case XK_Return: case XK_KP_Enter: chewing_handle_Enter (g_pChewingCtx); break; case XK_Delete: case XK_KP_Delete: chewing_handle_Del (g_pChewingCtx); break; case XK_BackSpace: chewing_handle_Backspace (g_pChewingCtx); break; case XK_Up: case XK_KP_Up: chewing_handle_Up (g_pChewingCtx); break; case XK_Down: case XK_KP_Down: chewing_handle_Down (g_pChewingCtx); break; case XK_Left: case XK_KP_Left: chewing_handle_Left (g_pChewingCtx); break; case XK_Right: case XK_KP_Right: chewing_handle_Right (g_pChewingCtx); break; #if 0 case XK_Shift_L: chewing_handle_ShiftLeft (g_pChewingCtx); break; case XK_Shift_R: chewing_handle_ShiftRight (g_pChewingCtx); break; #endif case XK_Tab: chewing_handle_Tab (g_pChewingCtx); break; default: if (nKeyVal > 32 && nKeyVal < 127) chewing_handle_Default (g_pChewingCtx, nKeyVal); break; } gcin_label_clear (MAX_SEG_NUM); g_nCurrentCursorPos = chewing_cursor_Current (g_pChewingCtx); if (g_nCurrentCursorPos < 0 || g_nCurrentCursorPos > MAX_SEG_NUM) return FALSE; // zuin symbols pszTmp = chewing_zuin_String (g_pChewingCtx, &nZuinLen); if (pszTmp) { for (nBufIdx = 0; nBufIdx < nZuinLen; nBufIdx++) { memcpy (szWord, pszTmp + nBufIdx * 3, 3); for (nPhoIdx = 0; nPhoIdx < 3; nPhoIdx++) if (strstr (g_gcinModMainFuncs.mf_pho_chars[nPhoIdx], szWord) != NULL) gcin_label_show (szWord, nPhoIdx + chewing_buffer_Len (g_pChewingCtx) + 1); } free (pszTmp); } // check if the composing is valid or not if (chewing_buffer_Check (g_pChewingCtx)) { g_gcinModMainFuncs.mf_hide_selections_win (); pszTmp = chewing_buffer_String (g_pChewingCtx); // init cand_no chewing_cand_Enumerate (g_pChewingCtx); g_gcinModMainFuncs.mf_clear_sele (); if (chewing_cand_TotalChoice (g_pChewingCtx)) { nIdx = 0; while (chewing_cand_hasNext (g_pChewingCtx)) { pszChewingCand = chewing_cand_String (g_pChewingCtx); if (nIdx > chewing_get_candPerPage (g_pChewingCtx) - 1) break; gcin_label_cand_show (pszChewingCand, nIdx++); free (pszChewingCand); } } for (nIdx = 0; nIdx < chewing_buffer_Len (g_pChewingCtx); nIdx++) { memcpy (szWord, pszTmp + (nIdx * 3), 3); gcin_label_show (szWord, nIdx); } free (pszTmp); } if (chewing_commit_Check (g_pChewingCtx)) { pszTmp = chewing_commit_String (g_pChewingCtx); g_gcinModMainFuncs.mf_send_text (pszTmp); // FIXME: workaround for repeated commit // it impacts the bEscCleanAllBuf setting! chewing_handle_Esc (g_pChewingCtx); free (pszTmp); } module_show_win (); return TRUE; }
int module_init_win (GCIN_module_main_functions *pFuncs) { GtkWidget *pErrDialog = NULL; int nIdx; int nSegSize = 0; if (!pFuncs) return FALSE; g_gcinModMainFuncs = *pFuncs; g_gcinModMainFuncs.mf_set_tsin_pho_mode (); g_gcinModMainFuncs.mf_set_win1_cb ((cb_selec_by_idx_t)select_idx, prev_page, next_page); if (g_pWinChewing) return TRUE; if (!chewing_initialize ()) { pErrDialog = gtk_message_dialog_new (NULL, GTK_DIALOG_MODAL, GTK_MESSAGE_ERROR, GTK_BUTTONS_CLOSE, "chewing init failed"); gtk_dialog_run (GTK_DIALOG (pErrDialog)); gtk_widget_destroy (pErrDialog); return FALSE; } g_pWinChewing = gtk_window_new (GTK_WINDOW_TOPLEVEL); gtk_window_set_has_resize_grip (GTK_WINDOW (g_pWinChewing), FALSE); gtk_window_set_resizable(GTK_WINDOW(g_pWinChewing), FALSE); gtk_window_set_default_size (GTK_WINDOW (g_pWinChewing), 32, 12); gtk_widget_realize (g_pWinChewing); g_gcinModMainFuncs.mf_set_no_focus (g_pWinChewing); g_pEvBoxChewing = gtk_event_box_new (); gtk_event_box_set_visible_window (GTK_EVENT_BOX(g_pEvBoxChewing), FALSE); if (!g_pEvBoxChewing) return FALSE; gtk_container_add (GTK_CONTAINER (g_pWinChewing), g_pEvBoxChewing); g_pHBoxChewing = gtk_hbox_new (FALSE, 0); if (!g_pHBoxChewing) return FALSE; gtk_container_add (GTK_CONTAINER (g_pEvBoxChewing), g_pHBoxChewing); // TODO: not sure if we need the mouse CB or not... // if we add the CB here, then it seems that we have to use gdk // it seems not so important...? do it later //g_signal_connect (G_OBJECT (g_pEvBoxChewing), "button-press-event", // G_CALLBACK (mouse_button_callback), NULL); if (!g_pSeg) { nSegSize = sizeof (SEG) * MAX_SEG_NUM; g_pSeg = malloc (nSegSize); memset (g_pSeg, 0, nSegSize); } for (nIdx = 0; nIdx < MAX_SEG_NUM; nIdx++) { g_pSeg[nIdx].label = gtk_label_new (NULL); gtk_widget_show (g_pSeg[nIdx].label); gtk_box_pack_start (GTK_BOX (g_pHBoxChewing), g_pSeg[nIdx].label, FALSE, FALSE, 0); } if (!g_gcinModMainFuncs.mf_phkbm->selkeyN) g_gcinModMainFuncs.mf_load_tab_pho_file(); gtk_widget_show_all (g_pWinChewing); g_gcinModMainFuncs.mf_init_tsin_selection_win (); module_change_font_size (); module_hide_win (); return TRUE; }
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; }
int module_init_win(GCIN_module_main_functions *funcs) { gmf = *funcs; // dbg("module_init_win\n"); gmf.mf_set_tsin_pho_mode(); gmf.mf_set_win1_cb((cb_selec_by_idx_t)select_idx, prev_page, next_page); if (win_anthy) return TRUE; if (anthy_init() == -1) { gmf.mf_box_warn("anthy_init() failed. Anthy not installed or incompatible anthy.so ?"); return FALSE; } ac = anthy_create_context(); if (!ac) { gmf.mf_box_warn("anthy_create_context error"); return FALSE; } anthy_context_set_encoding(ac, ANTHY_UTF8_ENCODING); win_anthy = gtk_window_new (GTK_WINDOW_TOPLEVEL); gtk_window_set_has_resize_grip(GTK_WINDOW(win_anthy), FALSE); gtk_window_set_resizable(GTK_WINDOW(win_anthy), FALSE); gtk_window_set_default_size(GTK_WINDOW (win_anthy), 40, 50); gtk_widget_realize (win_anthy); gmf.mf_set_no_focus(win_anthy); event_box_anthy = gtk_event_box_new(); gtk_event_box_set_visible_window (GTK_EVENT_BOX(event_box_anthy), FALSE); gtk_container_add(GTK_CONTAINER(win_anthy), event_box_anthy); GtkWidget *hbox_top = gtk_hbox_new (FALSE, 0); gtk_container_add(GTK_CONTAINER(event_box_anthy), hbox_top); g_signal_connect(G_OBJECT(event_box_anthy),"button-press-event", G_CALLBACK(mouse_button_callback), NULL); if (!seg) { int n=sizeof(SEG)*MAX_SEG_N; seg=malloc(n); bzero(seg, n); } int i; for(i=0; i < MAX_SEG_N; i++) { seg[i].label = gtk_label_new(NULL); gtk_widget_show(seg[i].label); gtk_box_pack_start (GTK_BOX (hbox_top), seg[i].label, FALSE, FALSE, 0); } gtk_widget_show_all(win_anthy); gmf.mf_init_tsin_selection_win(); module_change_font_size(); if (!gmf.mf_phkbm->selkeyN) gmf.mf_load_tab_pho_file(); module_hide_win(); return TRUE; }