Esempio n. 1
0
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);
    }
}
Esempio n. 2
0
static int
set_page_candidates(uim_context context, candidate_info *cand)
{
  int i, nr_in_page, start;

  start = cand->page_index * cand->disp_limit;
  if (cand->disp_limit && ((cand->num - start) > cand->disp_limit))
    nr_in_page = cand->disp_limit;
  else
    nr_in_page = cand->num - start;

  for (i = start; i < (start + nr_in_page); i++) {
    uim_candidate u_cand;

    u_cand = uim_get_candidate(context, i, cand->disp_limit ?
					   i % cand->disp_limit :
					   i);
    free(cand->cand_array[i].str);
    free(cand->cand_array[i].label);
    cand->cand_array[i].str = uim_strdup(uim_candidate_get_cand_str(u_cand));
    cand->cand_array[i].label = uim_strdup(uim_candidate_get_heading_label(u_cand));
    uim_candidate_free(u_cand);
  }

  return 1;
}
Esempio n. 3
0
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;
}
Esempio n. 4
0
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);
        }
    }
}
Esempio n. 5
0
int
new_candidate(uim_context context, candidate_info *cand, int num, int limit)
{
  int i;
#if !UIM_EL_USE_NEW_PAGE_HANDLING
  uim_candidate u_cand;
#endif

  if (cand->valid) clear_candidate(cand);

  cand->valid = 1;

  cand->index = -1;
  cand->disp_limit = limit;
  cand->num = num;
#if UIM_EL_USE_NEW_PAGE_HANDLING
  cand->page_index = 0;
#endif

  cand->cand_array = uim_malloc(sizeof(candidate) * num);

#if !UIM_EL_USE_NEW_PAGE_HANDLING
  /* get candidates from context */
  for (i = 0; i < num; i ++) {
	u_cand = uim_get_candidate(context, i, limit ? i % limit : i);
	cand->cand_array[i].str = uim_strdup(uim_candidate_get_cand_str(u_cand));
	cand->cand_array[i].label = uim_strdup(uim_candidate_get_heading_label(u_cand));
	uim_candidate_free(u_cand);
  }
#else
  for (i = 0; i < num; i++) {
	cand->cand_array[i].str = NULL;
	cand->cand_array[i].label = NULL;
  }
  set_page_candidates(context, cand);
#endif

  return 1;
}
Esempio n. 6
0
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);
}
Esempio n. 7
0
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");
}
Esempio n. 8
0
void InputContext::candidate_activate(int nr, int display_limit)
{
    int i;
#if !UIM_XIM_USE_NEW_PAGE_HANDLING
    const char *cand_str;
    const char *heading_label;
    const char *annotation_str;
    char *str;
#else
    std::vector<CandList>::iterator slot_it;
#endif
    std::vector<const char *> candidates;
    std::vector<const char *>::iterator it;

#if UIM_XIM_USE_DELAY
    timer_cancel();
#endif
    Canddisp *disp = canddisp_singleton();

    mDisplayLimit = display_limit;
    if (display_limit)
	mNumPage = (nr - 1) / display_limit + 1;
#if !UIM_XIM_USE_NEW_PAGE_HANDLING
    /* remove old data */
    if (!active_candidates.empty()) {
	for (it = active_candidates.begin();
	     it != active_candidates.end();
	     ++it)
	    free((char *)*it);
    }
    active_candidates.clear();
    for (i = 0; i < nr; i++) {
	uim_candidate cand;
	cand = uim_get_candidate(mUc, i,
			display_limit ? i % display_limit : i);
	cand_str = uim_candidate_get_cand_str(cand);
	heading_label = uim_candidate_get_heading_label(cand);
	annotation_str = uim_candidate_get_annotation(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);
    }
    disp->activate(candidates, display_limit);
    active_candidates = candidates;
#else /* !UIM_XIM_USE_NEW_PAGE_HANDLING */
    mNumCandidates = nr;
    /* remove old data */
    for (slot_it = mCandidateSlot.begin();
	 slot_it != mCandidateSlot.end();
	 ++slot_it) {
	if (*slot_it != (CandList)0) {
	    for (it = (*slot_it).begin(); it != (*slot_it).end(); ++it)
		free((char *)*it);
	}
    }
    mCandidateSlot.clear();

    /* setup dummy data */
    for (i = 0; i < mNumPage; i++)
    	mCandidateSlot.push_back((CandList)0);

    prepare_page_candidates(0);
    disp->set_nr_candidates(nr, display_limit);
    disp->set_page_candidates(0, mCandidateSlot[0]);
    disp->show_page(0);
#endif /* !UIM_XIM_USE_NEW_PAGE_HANDLING */
    mCandwinActive = true;

    current_cand_selection = 0;
    current_page = 0;
    need_hilite_selected_cand = false;
}