static gchar* h_ibus_text_get_substring (IBusText* ibus_text, glong p1, glong p2) { const gchar* text; const gchar* begin; const gchar* end; gchar* substring; glong limit; glong pos; glong n; text = ibus_text_get_text (ibus_text); limit = ibus_text_get_length (ibus_text) + 1; if (text == NULL || limit == 0) return NULL; p1 = MAX(0, p1); p2 = MAX(0, p2); pos = MIN(p1, p2); n = ABS(p2 - p1); if (pos + n > limit) n = limit - pos; begin = g_utf8_offset_to_pointer (text, pos); end = g_utf8_offset_to_pointer (begin, n); substring = g_strndup (begin, end - begin); return substring; }
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_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(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); } }
static void ibus_m17n_engine_callback (MInputContext *context, MSymbol command) { IBusM17NEngine *m17n = NULL; m17n = context->arg; g_return_if_fail (m17n != NULL); /* the callback may be called in minput_create_ic, in the time * m17n->context has not be assigned, so need assign it. */ if (m17n->context == NULL) { m17n->context = context; } if (command == Minput_preedit_start) { ibus_engine_hide_preedit_text ((IBusEngine *)m17n); } else if (command == Minput_preedit_draw) { ibus_m17n_engine_update_preedit (m17n); } else if (command == Minput_preedit_done) { ibus_engine_hide_preedit_text ((IBusEngine *)m17n); } else if (command == Minput_status_start) { ibus_engine_hide_preedit_text ((IBusEngine *)m17n); } else if (command == Minput_status_draw) { gchar *status; status = ibus_m17n_mtext_to_utf8 (m17n->context->status); if (status && strlen (status)) { IBusText *text; text = ibus_text_new_from_string (status); ibus_property_set_label (m17n->status_prop, text); ibus_property_set_visible (m17n->status_prop, TRUE); } else { ibus_property_set_label (m17n->status_prop, NULL); ibus_property_set_visible (m17n->status_prop, FALSE); } ibus_engine_update_property ((IBusEngine *)m17n, m17n->status_prop); g_free (status); } else if (command == Minput_status_done) { } else if (command == Minput_candidates_start) { ibus_engine_hide_lookup_table ((IBusEngine *) m17n); ibus_engine_hide_auxiliary_text ((IBusEngine *) m17n); } else if (command == Minput_candidates_draw) { ibus_m17n_engine_update_lookup_table (m17n); } else if (command == Minput_candidates_done) { ibus_engine_hide_lookup_table ((IBusEngine *) m17n); ibus_engine_hide_auxiliary_text ((IBusEngine *) m17n); } else if (command == Minput_set_spot) { } else if (command == Minput_toggle) { } else if (command == Minput_reset) { } /* ibus_engine_get_surrounding_text is only available in the current git master (1.3.99+) */ #ifdef HAVE_IBUS_ENGINE_GET_SURROUNDING_TEXT else if (command == Minput_get_surrounding_text && (((IBusEngine *) m17n)->client_capabilities & IBUS_CAP_SURROUNDING_TEXT) != 0) { IBusText *text; guint cursor_pos, nchars, nbytes; MText *mt, *surround; int len, pos; ibus_engine_get_surrounding_text ((IBusEngine *) m17n, &text, &cursor_pos); nchars = ibus_text_get_length (text); nbytes = g_utf8_offset_to_pointer (text->text, nchars) - text->text; mt = mconv_decode_buffer (Mcoding_utf_8, text->text, nbytes); g_object_unref (text); len = (long) mplist_value (m17n->context->plist); if (len < 0) { pos = cursor_pos + len; if (pos < 0) pos = 0; surround = mtext_duplicate (mt, pos, cursor_pos); } else if (len > 0) { pos = cursor_pos + len; if (pos > nchars) pos = nchars; surround = mtext_duplicate (mt, cursor_pos, pos); } else { surround = mtext (); } m17n_object_unref (mt); mplist_set (m17n->context->plist, Mtext, surround); m17n_object_unref (surround); } #endif /* !HAVE_IBUS_ENGINE_GET_SURROUNDING_TEXT */ else if (command == Minput_delete_surrounding_text && (((IBusEngine *) m17n)->client_capabilities & IBUS_CAP_SURROUNDING_TEXT) != 0) { int len; len = (long) mplist_value (m17n->context->plist); if (len < 0) ibus_engine_delete_surrounding_text ((IBusEngine *) m17n, len, -len); else if (len > 0) ibus_engine_delete_surrounding_text ((IBusEngine *) m17n, 0, len); } }