void FcitxKkcOnClose(void* arg, FcitxIMCloseEventType event) { FcitxKkc *kkc = (FcitxKkc*)arg; if (event == CET_LostFocus) { // TODO } else if (event == CET_ChangeByUser) { kkc_context_reset(kkc->context); } else if (event == CET_ChangeByInactivate) { KkcSegmentList* segments = kkc_context_get_segments(kkc->context); FcitxGlobalConfig* config = FcitxInstanceGetGlobalConfig(kkc->owner); if (config->bSendTextWhenSwitchEng) { FcitxMessagesSetMessageCount(kkc->tempMsg, 0); if (kkc_segment_list_get_cursor_pos(segments) >= 0) { int i = 0; for (i = 0; i < kkc_segment_list_get_size(segments); i ++) { KkcSegment* segment = kkc_segment_list_get(segments, i); const gchar* str = kkc_segment_get_output(segment); FcitxMessagesAddMessageAtLast(kkc->tempMsg, MSG_INPUT, "%s", str); } } else { gchar* str = kkc_context_get_input(kkc->context); FcitxMessagesAddMessageAtLast(kkc->tempMsg, MSG_INPUT, "%s", str); g_free(str); } if (FcitxMessagesGetMessageCount(kkc->tempMsg) > 0) { char* commit = FcitxUIMessagesToCString(kkc->tempMsg); FcitxInstanceCommitString(kkc->owner, FcitxInstanceGetCurrentIC(kkc->owner), commit); free(commit); } } kkc_context_reset(kkc->context); } }
static void _vala_kkc_segment_get_property (GObject * object, guint property_id, GValue * value, GParamSpec * pspec) { KkcSegment * self; self = G_TYPE_CHECK_INSTANCE_CAST (object, KKC_TYPE_SEGMENT, KkcSegment); switch (property_id) { case KKC_SEGMENT_INPUT: g_value_set_string (value, kkc_segment_get_input (self)); break; case KKC_SEGMENT_OUTPUT: g_value_set_string (value, kkc_segment_get_output (self)); break; default: G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec); break; } }
INPUT_RETURN_VALUE FcitxKkcGetCandWords(void* arg) { FcitxKkc *kkc = (FcitxKkc*)arg; FcitxInputState* input = FcitxInstanceGetInputState(kkc->owner); FcitxCandidateWordList* candList = FcitxInputStateGetCandidateList(input); FcitxMessages* clientPreedit = FcitxInputStateGetClientPreedit(input); FcitxMessages* preedit = FcitxInputStateGetPreedit(input); FcitxInstanceCleanInputWindow(kkc->owner); FcitxMessages* message = FcitxInstanceICSupportPreedit(kkc->owner, FcitxInstanceGetCurrentIC(kkc->owner)) ? clientPreedit : preedit; FcitxCandidateWordSetChoose(candList, DIGIT_STR_CHOOSE); FcitxCandidateWordSetPageSize(candList, kkc->config.pageSize); FcitxCandidateWordSetLayoutHint(candList, kkc->config.candidateLayout); FcitxInputStateSetShowCursor(input, true); KkcSegmentList* segments = kkc_context_get_segments(kkc->context); if (kkc_segment_list_get_cursor_pos(segments) >= 0) { int i = 0; int offset = 0; for (i = 0; i < kkc_segment_list_get_size(segments); i ++) { KkcSegment* segment = kkc_segment_list_get(segments, i); const gchar* str = kkc_segment_get_output(segment); FcitxMessageType messageType = MSG_INPUT; if (i < kkc_segment_list_get_cursor_pos(segments)) { offset += strlen(str); } if (i == kkc_segment_list_get_cursor_pos(segments)) { messageType = (FcitxMessageType) (MSG_HIGHLIGHT | MSG_OTHER); } FcitxMessagesAddMessageAtLast(message, messageType, "%s", str); } if (message == clientPreedit) { FcitxInputStateSetClientCursorPos(input, offset); } else { FcitxInputStateSetCursorPos(input, offset); } } else { gchar* str = kkc_context_get_input(kkc->context); if (str && str[0]) { FcitxMessagesAddMessageAtLast(message, MSG_INPUT, "%s", str); if (message == clientPreedit) { FcitxInputStateSetClientCursorPos(input, strlen(str)); } else { FcitxInputStateSetCursorPos(input, strlen(str)); } } g_free(str); } KkcCandidateList* kkcCandidates = kkc_context_get_candidates(kkc->context); if (kkc_candidate_list_get_page_visible(kkcCandidates)) { int i, j; guint size = kkc_candidate_list_get_size(kkcCandidates); gint cursor_pos = kkc_candidate_list_get_cursor_pos(kkcCandidates); guint page_start = kkc_candidate_list_get_page_start(kkcCandidates); guint page_size = kkc_candidate_list_get_page_size(kkcCandidates); for (i = kkc_candidate_list_get_page_start(kkcCandidates), j = 0; i < size; i ++, j++) { FcitxCandidateWord word; word.callback = FcitxKkcGetCandWord; word.extraType = MSG_OTHER; word.owner = kkc; int* id = fcitx_utils_new(int); *id = j; word.priv = id; word.strExtra = NULL; word.strExtra = MSG_TIPS; KkcCandidate* kkcCandidate = kkc_candidate_list_get(kkcCandidates, i); if (kkc->config.showAnnotation && kkc_candidate_get_annotation(kkcCandidate)) { fcitx_utils_alloc_cat_str(word.strExtra, " [", kkc_candidate_get_annotation(kkcCandidate), "]"); } word.strWord = strdup(kkc_candidate_get_text(kkcCandidate)); if (i == cursor_pos) { word.wordType = MSG_CANDIATE_CURSOR; } else { word.wordType = MSG_OTHER; } FcitxCandidateWordAppend(candList, &word); } FcitxCandidateWordSetFocus(candList, cursor_pos - page_start); FcitxCandidateWordSetOverridePaging(candList, (cursor_pos - page_start) >= page_size, (size - page_start) / page_size != (cursor_pos - page_start) / page_size, FcitxKkcPaging, kkc, NULL); } if (kkc_context_has_output(kkc->context)) { gchar* str = kkc_context_poll_output(kkc->context); FcitxInstanceCommitString(kkc->owner, FcitxInstanceGetCurrentIC(kkc->owner), str); g_free(str); } return IRV_DISPLAY_CANDWORDS; }