Example #1
0
void
StandardIMInstance::imm_update_candidates_list (const IME_InputContext   *ic,
                                                const IME_CandidatesList *candidates)
{
    if (ic && ic->id >= 0 && candidates) {
        StandardIMInstance *inst = __global->find_instance (ic->id);
        if (inst) {
            inst->m_lookup_table.clear ();
            if (candidates->nr_candidates > 0 && candidates->candidates) {

                std::vector <WideString> labels;
                AttributeList attrs;
                WideString wstr;

                if ((candidates->page_state & IME_FIRST_PAGE) == 0)
                    inst->m_lookup_table.append_candidate ((ucs4_t) 0x20);

                for (int i = 0; i < candidates->nr_candidates; ++i) {
                    labels.push_back (inst->m_factory->convert_string (String (candidates->candidates [i].label)));

                    attrs.clear ();

                    for (int j = 0; j < candidates->candidates [i].content.nr_attributes; ++j)
                        attrs.push_back (convert_attribute (candidates->candidates [i].content.attributes [j]));

                    wstr = inst->m_factory->convert_string (String (candidates->candidates [i].content.string));
                    inst->m_lookup_table.append_candidate (wstr, attrs);
                }

                if ((candidates->page_state & IME_LAST_PAGE) == 0)
                    inst->m_lookup_table.append_candidate ((ucs4_t) 0x20);

                if ((candidates->page_state & IME_FIRST_PAGE) == 0) {
                    inst->m_lookup_table.set_page_size (1);
                    inst->m_lookup_table.page_down ();
                }

                inst->m_lookup_table.set_page_size (candidates->nr_candidates);
                inst->m_lookup_table.set_candidate_labels (labels);

                if (candidates->focused_candidate >= 0 && candidates->focused_candidate < candidates->nr_candidates)
                    inst->m_lookup_table.set_cursor_pos_in_current_page (candidates->focused_candidate);
            }

            inst->update_lookup_table (inst->m_lookup_table);
        }
    }
}