IBusText *decorate_pre_edit(IBusChewingPreEdit * icPreEdit, IBusCapabilite capabilite) { gchar *preEdit = ibus_chewing_pre_edit_get_pre_edit(icPreEdit); IBusText *iText = g_object_ref_sink(ibus_text_new_from_string(preEdit)); gint chiSymbolCursor = chewing_cursor_Current(icPreEdit->context); IBUS_CHEWING_LOG(DEBUG, "decorate_pre_edit() cursor=%d preEdit=%s", chiSymbolCursor, preEdit); gint charLen = (gint) g_utf8_strlen(preEdit, -1); gint cursorRight = chiSymbolCursor + icPreEdit->bpmfLen; IBUS_CHEWING_LOG(DEBUG, "decorate_pre_edit() charLen=%d cursorRight=%d", charLen, cursorRight); IntervalType it; chewing_interval_Enumerate(icPreEdit->context); /* Add double lines on chewing interval that contains cursor */ /* Add single line on other chewing interval */ while (chewing_interval_hasNext(icPreEdit->context)) { chewing_interval_Get(icPreEdit->context, &it); if (it.from <= chiSymbolCursor && chiSymbolCursor <= it.to) { ibus_text_append_attribute(iText, IBUS_ATTR_TYPE_UNDERLINE, IBUS_ATTR_UNDERLINE_DOUBLE, it.from, it.to + 1); } else { ibus_text_append_attribute(iText, IBUS_ATTR_TYPE_UNDERLINE, IBUS_ATTR_UNDERLINE_SINGLE, it.from, it.to + 1); } } if (!mkdg_has_flag(capabilite, IBUS_CAP_SURROUNDING_TEXT) || !mkdg_has_flag(capabilite, IBUS_CAP_AUXILIARY_TEXT)) { /* Cannot change color when if the client is not capable * of showing surrounding text or auxiliary text */ return iText; } /* Show current cursor in red */ ibus_text_append_attribute(iText, IBUS_ATTR_TYPE_BACKGROUND, 0x00ff0000, chiSymbolCursor, chiSymbolCursor + 1); return iText; }
static void ibus_hangul_engine_update_preedit_text (IBusHangulEngine *hangul) { const ucschar *hic_preedit; IBusText *text; UString *preedit; gint preedit_len; // ibus-hangul's preedit string is made up of ibus context's // internal preedit string and libhangul's preedit string. // libhangul only supports one syllable preedit string. // In order to make longer preedit string, ibus-hangul maintains // internal preedit string. hic_preedit = hangul_ic_get_preedit_string (hangul->context); preedit = ustring_dup (hangul->preedit); preedit_len = ustring_length(preedit); ustring_append_ucs4 (preedit, hic_preedit, -1); if (ustring_length(preedit) > 0) { IBusPreeditFocusMode preedit_option = IBUS_ENGINE_PREEDIT_COMMIT; if (hangul->hanja_list != NULL) preedit_option = IBUS_ENGINE_PREEDIT_CLEAR; text = ibus_text_new_from_ucs4 ((gunichar*)preedit->data); // ibus-hangul's internal preedit string ibus_text_append_attribute (text, IBUS_ATTR_TYPE_UNDERLINE, IBUS_ATTR_UNDERLINE_SINGLE, 0, preedit_len); // Preedit string from libhangul context. // This is currently composing syllable. ibus_text_append_attribute (text, IBUS_ATTR_TYPE_FOREGROUND, 0x00ffffff, preedit_len, -1); ibus_text_append_attribute (text, IBUS_ATTR_TYPE_BACKGROUND, 0x00000000, preedit_len, -1); ibus_engine_update_preedit_text_with_mode ((IBusEngine *)hangul, text, ibus_text_get_length (text), TRUE, preedit_option); } else { text = ibus_text_new_from_static_string (""); ibus_engine_update_preedit_text ((IBusEngine *)hangul, text, 0, FALSE); } ustring_delete(preedit); }
static void ibus_unikey_engine_update_preedit_string(IBusEngine *engine, const gchar *string, gboolean visible) { IBusText *text; text = ibus_text_new_from_static_string(string); // underline text ibus_text_append_attribute(text, IBUS_ATTR_TYPE_UNDERLINE, IBUS_ATTR_UNDERLINE_SINGLE, 0, -1); // update and display text ibus_engine_update_preedit_text_with_mode(engine, text, ibus_text_get_length(text), visible, IBUS_ENGINE_PREEDIT_COMMIT); }
static void ibus_m17n_engine_update_preedit (IBusM17NEngine *m17n) { IBusText *text; gchar *buf; IBusM17NEngineClass *klass = (IBusM17NEngineClass *) G_OBJECT_GET_CLASS (m17n); buf = ibus_m17n_mtext_to_utf8 (m17n->context->preedit); if (buf) { text = ibus_text_new_from_static_string (buf); if (klass->preedit_foreground != INVALID_COLOR) ibus_text_append_attribute (text, IBUS_ATTR_TYPE_FOREGROUND, klass->preedit_foreground, 0, -1); if (klass->preedit_background != INVALID_COLOR) ibus_text_append_attribute (text, IBUS_ATTR_TYPE_BACKGROUND, klass->preedit_background, 0, -1); ibus_text_append_attribute (text, IBUS_ATTR_TYPE_UNDERLINE, klass->preedit_underline, 0, -1); ibus_engine_update_preedit_text ((IBusEngine *) m17n, text, m17n->context->cursor_pos, mtext_len (m17n->context->preedit) > 0); } }
static void ibus_unikey_engine_update_preedit_string(IBusEngine *engine, const gchar *string, gboolean visible) { IBusText *text; text = ibus_text_new_from_static_string(string); // underline text ibus_text_append_attribute(text, IBUS_ATTR_TYPE_UNDERLINE, IBUS_ATTR_UNDERLINE_SINGLE, 0, -1); // update and display text ibus_engine_update_preedit_text(engine, text, ibus_text_get_length(text), visible); // every time have preedit text -> unlock mutex -> start capture mouse if (unikey->mouse_capture) { // unlock capture thread (start capture) pthread_mutex_unlock(&mutex_mcap); } }