// 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; }
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; }