static void candidate_activate_cb(void *ptr, int nr, int display_limit) { ic_t *ic = (ic_t *)ptr; int i; uim_candidate cand; ic->cand_nr = nr; ic->cand_limit = display_limit; if (debug) fprintf(stderr, "candidate_activate: nr=%d display_limit=%d\n", nr, display_limit); vp_iobuf_put_str(iobuf, "candidate_activate"); /* "candidate", pagesize, candlen, [label, str, annotation], ... */ vp_iobuf_put_str(iobuf, "candidate"); vp_iobuf_put_num(iobuf, display_limit); vp_iobuf_put_num(iobuf, nr); for (i = 0; i < nr; ++i) { cand = uim_get_candidate(ic->cx, i, 0); vp_iobuf_put_str(iobuf, uim_candidate_get_heading_label(cand)); vp_iobuf_put_str(iobuf, uim_candidate_get_cand_str(cand)); vp_iobuf_put_str(iobuf, uim_candidate_get_annotation_str(cand)); uim_candidate_free(cand); } }
void InputContext::prepare_page_candidates(int page) { int i; int page_nr, start; const char *cand_str; const char *heading_label; const char *annotation_str; char *str; CandList candidates; if (page < 0) return; if (mCandidateSlot[page] != (CandList)0) return; start = page * mDisplayLimit; if (mDisplayLimit && (mNumCandidates - start) > mDisplayLimit) page_nr = mDisplayLimit; else page_nr = mNumCandidates - start; for (i = 0; i < page_nr; i++) { uim_candidate cand; cand = uim_get_candidate(mUc, (i + start), mDisplayLimit ? (i + start) % mDisplayLimit : (i + start)); cand_str = uim_candidate_get_cand_str(cand); heading_label = uim_candidate_get_heading_label(cand); annotation_str = uim_candidate_get_annotation_str(cand); if (cand_str && heading_label && annotation_str) { str = (char *)malloc(strlen(cand_str) + strlen(heading_label) + strlen(annotation_str) + 3); sprintf(str, "%s\a%s\a%s", heading_label, cand_str, annotation_str); candidates.push_back((const char *)str); } else { fprintf(stderr, "Warning: cand_str at %d is NULL\n", i); candidates.push_back((const char *)strdup("\a\a")); } uim_candidate_free(cand); } mCandidateSlot[page] = candidates; }
void uim_cand_win_gtk_set_page_candidates(UIMCandWinGtk *cwin, guint page, GSList *candidates) { GtkListStore *store; GSList *node; gint j, len; g_return_if_fail(UIM_IS_CAND_WIN_GTK(cwin)); if (candidates == NULL) return; cwin->sub_window.active = FALSE; len = g_slist_length(candidates); /* create GtkListStores, and set candidates */ store = gtk_list_store_new(NR_COLUMNS, G_TYPE_STRING, G_TYPE_STRING, G_TYPE_STRING); cwin->stores->pdata[page] = store; /* set candidates */ for (j = 0, node = g_slist_nth(candidates, j); j < len; j++, node = g_slist_next(node)) { GtkTreeIter ti; if (node) { uim_candidate cand = node->data; gtk_list_store_append(store, &ti); gtk_list_store_set(store, &ti, COLUMN_HEADING, uim_candidate_get_heading_label(cand), COLUMN_CANDIDATE, uim_candidate_get_cand_str(cand), COLUMN_ANNOTATION, uim_candidate_get_annotation_str(cand), TERMINATOR); } } }
void uim_cand_win_gtk_set_candidates(UIMCandWinGtk *cwin, guint display_limit, GSList *candidates) { gint i, nr_stores = 1; g_return_if_fail(UIM_IS_CAND_WIN_GTK(cwin)); if (cwin->stores == NULL) cwin->stores = g_ptr_array_new(); /* remove old data */ if (cwin->page_index >= 0 && cwin->page_index < (int) cwin->stores->len) { /* Remove data from current page to shrink the window */ if (cwin->stores->pdata[cwin->page_index]) gtk_list_store_clear(cwin->stores->pdata[cwin->page_index]); } for (i = cwin->stores->len - 1; i >= 0; i--) { GtkListStore *store = g_ptr_array_remove_index(cwin->stores, i); if (store) g_object_unref(G_OBJECT(store)); } cwin->candidate_index = -1; cwin->nr_candidates = g_slist_length(candidates); cwin->display_limit = display_limit; cwin->sub_window.active = FALSE; if (candidates == NULL) return; /* calculate number of GtkListStores to create */ if (display_limit) { nr_stores = cwin->nr_candidates / display_limit; if (cwin->nr_candidates > display_limit * nr_stores) nr_stores++; } /* create GtkListStores, and set candidates */ for (i = 0; i < nr_stores; i++) { GtkListStore *store = gtk_list_store_new(NR_COLUMNS, G_TYPE_STRING, G_TYPE_STRING, G_TYPE_STRING); GSList *node; guint j; g_ptr_array_add(cwin->stores, store); /* set candidates */ for (j = i * display_limit, node = g_slist_nth(candidates, j); display_limit ? j < display_limit * (i + 1) : j < cwin->nr_candidates; j++, node = g_slist_next(node)) { GtkTreeIter ti; if (node) { uim_candidate cand = node->data; gtk_list_store_append(store, &ti); gtk_list_store_set(store, &ti, COLUMN_HEADING, uim_candidate_get_heading_label(cand), COLUMN_CANDIDATE, uim_candidate_get_cand_str(cand), COLUMN_ANNOTATION, uim_candidate_get_annotation_str(cand), TERMINATOR); } else { #if 0 /* * 2004-07-22 Takuro Ashie <*****@*****.**> * * FIXME!: * I think we shoudn't set any data for empty row. * It may cause incorrect action. */ gtk_list_store_append(store, &ti); gtk_list_store_set(store, &ti, COLUMN_HEADING, "", COLUMN_CANDIDATE, "", COLUMN_ANNOTATION, NULL, TERMINATOR); #endif } } } if (cwin->nr_candidates <= cwin->display_limit) { gtk_widget_set_sensitive(GTK_WIDGET(cwin->prev_page_button), FALSE); gtk_widget_set_sensitive(GTK_WIDGET(cwin->next_page_button), FALSE); } else { gtk_widget_set_sensitive(GTK_WIDGET(cwin->prev_page_button), TRUE); gtk_widget_set_sensitive(GTK_WIDGET(cwin->next_page_button), TRUE); } uim_cand_win_gtk_set_page(cwin, 0); uim_cand_win_gtk_update_label(cwin); }
void CandidateWindowProxy::setPage(int page) { #ifdef ENABLE_DEBUG qDebug("setPage : page = %d", page); #endif // calculate page int lastpage = displayLimit ? nrCandidates / displayLimit : 0; int newpage; if (page < 0) newpage = lastpage; else if (page > lastpage) newpage = 0; else newpage = page; pageIndex = newpage; // calculate index int newindex; if (displayLimit) { newindex = (candidateIndex >= 0) ? (newpage * displayLimit) + (candidateIndex % displayLimit) : -1; } else { newindex = candidateIndex; } if (newindex >= nrCandidates) newindex = nrCandidates - 1; // set cand items // // If we switch to last page, the number of items to be added // is lower than displayLimit. // // ex. if nrCandidate == 14 and displayLimit == 10, the number of // last page's item == 4 int ncandidates = displayLimit; if (newpage == lastpage) ncandidates = nrCandidates - displayLimit * lastpage; QString candidateMessage; for (int i = 0; i < ncandidates; i++) { uim_candidate cand = stores.at(displayLimit * newpage + i); candidateMessage += QString::fromUtf8(uim_candidate_get_heading_label(cand)) + '\a' + QString::fromUtf8(uim_candidate_get_cand_str(cand)) + '\a' + QString::fromUtf8(uim_candidate_get_annotation_str(cand)) + '\f'; } execute("update_view\f" + QString::number(ncandidates) + "\f" + candidateMessage); // set index if (newindex != candidateIndex) setIndex(newindex); else updateLabel(); execute("update_size"); }