Beispiel #1
0
/* Lisp functions definition */

DEFUN ("canna-key-proc", Fcanna_key_proc, 1, 1, 0, /*
Translate a key input to a set of strings.  The strings contain both
well-formed string and intermediate result to show the translation
information to a user.  Converted strings are stored in specific
variables.
*/
       (ch))
{
  jrKanjiStatus ks;
  int len;

  CHECK_CHAR_COERCE_INT (ch);
  len = jrKanjiString (0, XCHAR (ch), key_buffer, KEYTOSTRSIZE, &ks);
  return storeResults (key_buffer, len, &ks);
}

static Lisp_Object
storeResults (unsigned char *buf, int len, jrKanjiStatus *ks)
{
  Lisp_Object val = Qnil;

  if (len < 0)
    { /* Error detected */
      val = make_string ((unsigned char*) jrKanjiError, strlen (jrKanjiError));
    }
  else
    {
      /* 確定した文字列 (the confirmed string) */
bool
CannaJRKanji::process_key_event (const KeyEvent &key)
{
    int size = 1024, n, ch;
    char buf[1024 + 1];

    if (match_key_event (m_canna->m_factory->m_on_off_key, key, 0)) {
        m_enabled = !m_enabled;
        set_mode_line ();
        m_canna->reset ();
        return true;
    }

    if (!m_enabled)
        return false;

    ch = translate_key_event (key);
    if (ch == 0xffff)
        return false;

    n = jrKanjiString (m_context_id, ch, buf, size, &m_ks);

    // commit string
    if (n > 0 && !(m_ks.info & KanjiThroughInfo)) {
        buf[n] = '\0';
        WideString dest;
        m_iconv.convert (dest, buf);
        m_canna->commit_string (dest);
    }

    // mode line string
    if (m_ks.info & KanjiModeInfo)
        set_mode_line ();

    // guide line string
    set_guide_line ();

    // preedit string
    if (m_ks.length > 0) {
        WideString dest;
        AttributeList attrs;
        unsigned int pos;
        pos = convert_string (dest, attrs,
                              (const char *) m_ks.echoStr,
                              m_ks.length,
                              m_ks.revPos,
                              m_ks.revLen);

        m_canna->update_preedit_string (dest, attrs);
        m_canna->update_preedit_caret (pos);

        if (!m_preediting && dest.length () <= 0) {
            m_canna->hide_preedit_string ();
            return !(m_ks.info & KanjiThroughInfo);
        } else {
            m_preediting = true;
            m_canna->show_preedit_string ();
            m_canna->hide_lookup_table ();
            return true;
        }

    } else if (m_ks.length == 0) {
        m_canna->update_preedit_string (utf8_mbstowcs (""));

        m_canna->hide_preedit_string ();
        m_canna->hide_lookup_table ();

        if (m_preediting) {
            m_preediting = false;
            return true;
        } else {
            return !(m_ks.info & KanjiThroughInfo);
        }
    }

    m_canna->hide_lookup_table ();

    return !(m_ks.info & KanjiThroughInfo);
}