void CandidateWindowProxy::slotReadyStandardOutput()
{
    QByteArray output = process->readAllStandardOutput();
    QList<QStringList> messageList = parse_messages(QString(output));
    for (int i = 0, j = messageList.count(); i < j; i++) {
        QStringList message = messageList[i];
        QString command = message[0];
        if (command == "set_candidate_index") {
            uim_set_candidate_index(ic->uimContext(), message[1].toInt());
        } else if (command == "set_candidate_index_2") {
            candidateIndex = pageIndex * displayLimit + message[1].toInt();
            uim_set_candidate_index(ic->uimContext(), candidateIndex);
        } else if (command == "set_candwin_active") {
            ic->setCandwinActive();
        } else if (command == "set_focus_widget") {
            setFocusWidget();
        } else if (command == "update_label") {
            updateLabel();
        }
#ifdef WORKAROUND_BROKEN_RESET_IN_QT4
        else if (command == "shown") {
            m_isVisible = true;
        } else if (command == "hidden") {
            m_isVisible = false;
        }
#endif
    }
}
Beispiel #2
0
static void
candidate_shift_page_cb(void *ptr, int direction)
{
    ic_t *ic = (ic_t *)ptr;

    if (debug) fprintf(stderr, "candidate_shift_page: direction=%d\n", direction);

    if (direction < 0) {
        /* to left */
        ic->cand_index -= ic->cand_limit;
        if (ic->cand_index < 0)
            ic->cand_index += ic->cand_nr;
    } else {
        /* to right */
        if (ic->cand_index / ic->cand_limit == (ic->cand_nr - 1) / ic->cand_limit)
            /* cursor is on last page. go to first page. */
            ic->cand_index = ic->cand_index % ic->cand_limit;
        else
            ic->cand_index += ic->cand_limit;
    }
    if (ic->cand_index >= ic->cand_nr)
        ic->cand_index = ic->cand_nr - 1;
    uim_set_candidate_index(ic->cx, ic->cand_index);

    /* XXX */
    candidate_activate_cb(ptr, ic->cand_nr, ic->cand_limit);
    candidate_select_cb(ptr, ic->cand_index);
}
void CandidateWindowProxy::shiftPage(bool forward)
{
#ifdef ENABLE_DEBUG
    qDebug("candidateIndex = %d", candidateIndex);
#endif
    
    if (forward) {
        if (candidateIndex != -1)
            candidateIndex += displayLimit;
        setPage(pageIndex + 1);
    } else {
        if (candidateIndex != -1) {
            if (candidateIndex < displayLimit)
                candidateIndex = displayLimit * (nrCandidates / displayLimit)
                    + candidateIndex;
            else
                candidateIndex -= displayLimit;
        }
        setPage(pageIndex - 1);
    }
    if (ic && ic->uimContext() && candidateIndex != -1)
        uim_set_candidate_index(ic->uimContext(), candidateIndex);
    // for CandidateWindow
    if (candidateIndex != -1) {
        int idx = displayLimit ? candidateIndex % displayLimit : candidateIndex;
        execute("shift_page\f" + QString::number(idx));
    }
}
Beispiel #4
0
static void candwin_read_cb(int fd, int /* ev */)
{
    char buf[1024];
    int n;

    n = static_cast<int>(read(fd, buf, 1024 - 1));
    if (n == 0) {
	terminate_canddisp_connection();
	return;
    }
    if (n == -1)
	return;
    buf[n] = '\0';

    if (!strcmp(buf, "err")) {
	terminate_canddisp_connection();
	return;
    }

    InputContext *focusedContext = InputContext::focusedContext();
    if (focusedContext) {
	char *line = buf;
	char *eol = strchr(line, '\n');
	if (eol != NULL)
	    *eol = '\0';

	if (strcmp("index", line) == 0) {
	    line = eol + 1;
	    eol = strchr(line, '\n');
	    if (eol != NULL)
		*eol = '\0';

	    int index;
	    sscanf(line, "%d", &index);
	    focusedContext->candidate_select(index);
	    uim_set_candidate_index(focusedContext->getUC(), index);
	    // send packet queue for drawing on-the-spot preedit strings
	    focusedContext->get_ic()->force_send_packet();
	}
    }
    return;
}
Beispiel #5
0
void InputContext::candidate_shift_page(int direction)
{
    int new_page;
    int new_index;

    if (mDisplayLimit) {
	if (direction)
	    new_page = current_page + 1;
	else
	    new_page = current_page - 1;

	if (new_page < 0)
	    current_page = mNumPage - 1;
	else if (new_page >= mNumPage)
	    current_page = 0;
	else
	    current_page = new_page;

	new_index = (current_page * mDisplayLimit) + (current_cand_selection % mDisplayLimit);

#if !UIM_XIM_USE_NEW_PAGE_HANDLING
	if (new_index >= active_candidates.size())
	    current_cand_selection = active_candidates.size() - 1;
#else
	if (new_index >= mNumCandidates)
	    current_cand_selection = mNumCandidates - 1;
#endif
	else
	    current_cand_selection = new_index;
#if UIM_XIM_USE_NEW_PAGE_HANDLING
    	Canddisp *disp = canddisp_singleton();
	prepare_page_candidates(current_page);
	disp->set_page_candidates(current_page, mCandidateSlot[current_page]);
#endif
    }
    candidate_select(current_cand_selection);
    if (need_hilite_selected_cand)
      uim_set_candidate_index(mUc, current_cand_selection);
}
Beispiel #6
0
void
shift_candidate_page(uim_context context, candidate_info *cand, int direction)
{
  int index;
#if UIM_EL_USE_NEW_PAGE_HANDLING
  int page, nr_pages;
#endif
  int is_first = 0, is_last = 0;

  debug_printf(DEBUG_NOTE, 
			   "candidate_shift_page_cb (direction: %d)\n", direction);

  if (!cand->disp_limit)
    return;

  index = cand->index;
#if UIM_EL_USE_NEW_PAGE_HANDLING
  page = cand->page_index;
#endif
  
#if !UIM_EL_USE_NEW_PAGE_HANDLING
  is_first = (index < cand->disp_limit);

  /*
   * ((cand.num - 1) / cand.disp_limit) + 1   : total pages
   * (index / cand.disp_limit)                : current page number
   */
  is_last = ((((cand->num - 1) / cand->disp_limit) + 1) 
			 == ((index / cand->disp_limit) + 1));
#else
  is_first = (page == 0);
  nr_pages = ((cand->num - 1) / cand->disp_limit) + 1;
  is_last = (nr_pages == page);
#endif

  if (direction) { /* forward */

	if (is_last) {
	  index = index % cand->disp_limit;
#if UIM_EL_USE_NEW_PAGE_HANDLING
	  cand->page_index = 0;
#endif
	}
	else {
	  index += cand->disp_limit;
#if UIM_EL_USE_NEW_PAGE_HANDLING
	  cand->page_index++;
#endif
	}

  } else { /* backward */

	if (is_first) {
	  index = (cand->num / cand->disp_limit) * cand->disp_limit + index;
#if UIM_EL_USE_NEW_PAGE_HANDLING
	  cand->page_index = nr_pages - 1;
#endif
	}
    else {
	  index -= cand->disp_limit;
#if UIM_EL_USE_NEW_PAGE_HANDLING
	  cand->page_index--;
#endif
    }
  }

  if (index < 0) index = 0;
  
  if (index >= cand->num) index = cand->num - 1;

  cand->index = index;

#if UIM_EL_USE_NEW_PAGE_HANDLING
  set_page_candidates(context, cand);
#endif
  uim_set_candidate_index(context, index);
}