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; }
gboolean property_context_write(PropertyContext * ctx, gpointer userData) { if (ctx == NULL) { return FALSE; } mkdg_log(DEBUG, "property_context_read(%s,-)", ctx->spec->key); if (mkdg_has_flag(ctx->spec->propertyFlags, MKDG_PROPERTY_FLAG_NO_BACKEND)) { return FALSE; } if (ctx->backend == NULL) { return FALSE; } return ctx->backend->writeFunc(ctx->backend, &(ctx->value), ctx->spec->subSection, ctx->spec->key, userData); }
/* assign: save then apply */ GValue *property_context_read(PropertyContext * ctx, gpointer userData) { if (ctx == NULL) { return NULL; } mkdg_log(DEBUG, "property_context_read(%s,-)", ctx->spec->key); if (mkdg_has_flag(ctx->spec->propertyFlags, MKDG_PROPERTY_FLAG_NO_BACKEND)) { return NULL; } if (ctx->backend == NULL) { return NULL; } GValue *result = mkdg_backend_read(ctx->backend, &(ctx->value), ctx->spec->subSection, ctx->spec->key, userData); if (result == NULL) { mkdg_log(WARN, "property_context_read(%s): failed to read key", ctx->spec->key); } return result; }