Ejemplo n.º 1
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;
}
Ejemplo n.º 2
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);
    }
}
Ejemplo n.º 3
0
CandidateWindowProxy::~CandidateWindowProxy()
{
    // clear stored candidate data
    while (!stores.isEmpty()) {
        uim_candidate cand = stores.takeFirst();
        if (cand)
            uim_candidate_free(cand);
    }
    process->close();
}
Ejemplo n.º 4
0
void CandidateWindowProxy::clearCandidates()
{
#ifdef ENABLE_DEBUG
    qDebug("clear Candidates");
#endif

    candidateIndex = -1;
    displayLimit = 0;
    nrCandidates = 0;

    // clear stored candidate data
    while (!stores.isEmpty()) {
        uim_candidate cand = stores.takeFirst();
        if (cand)
            uim_candidate_free(cand);
    }
}
Ejemplo n.º 5
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;
}
Ejemplo n.º 6
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;
}
Ejemplo n.º 7
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;
}