Commit 323f0787 authored by Hiroshi Sumita's avatar Hiroshi Sumita
Browse files

Modify Observer and implements some API.

BUG=None
TEST=Run a test.

Review URL: http://codereview.appspot.com/5309041
parent 838c4313
Loading
Loading
Loading
Loading
+5 −5
Original line number Diff line number Diff line
@@ -310,7 +310,7 @@ BopomofoContext::updateAuxiliaryText (void)
    if (G_UNLIKELY (m_text.empty () ||
        m_phrase_editor.candidates ().size () == 0)) {
        m_auxiliary_text = "";
        m_observer->auxiliaryTextChanged ();
        m_observer->auxiliaryTextChanged (this);
        return;
    }

@@ -349,7 +349,7 @@ BopomofoContext::updateAuxiliaryText (void)
    }

    m_auxiliary_text = m_buffer;
    m_observer->auxiliaryTextChanged ();
    m_observer->auxiliaryTextChanged (this);
}

void
@@ -384,7 +384,7 @@ BopomofoContext::commit ()
    m_phrase_editor.commit ();
    reset ();
    update ();
    m_observer->commitText (m_buffer);
    m_observer->commitText (this, m_buffer);
}

void
@@ -393,7 +393,7 @@ BopomofoContext::updatePreeditText (void)
    /* preedit text = selected phrases + highlight candidate + rest text */
    if (G_UNLIKELY (m_phrase_editor.empty () && m_text.empty ())) {
        m_preedit_text.clear ();
        m_observer->preeditTextChanged ();
        m_observer->preeditTextChanged (this);
        return;
    }

@@ -474,7 +474,7 @@ BopomofoContext::updatePreeditText (void)
        m_preedit_text.rest_text = m_buffer.substr (edit_end_byte);
    }

    m_observer->preeditTextChanged ();
    m_observer->preeditTextChanged (this);
}

static gint
+8 −5
Original line number Diff line number Diff line
@@ -56,7 +56,9 @@ enum VKeyCode {

    VKEY_CANDIDATE_SELECT = (30 << 8),
    VKEY_CANDIDATE_FOCUS = (31 << 8),
    VKEY_CANDIDATE_RESET = (32 << 8),
    VKEY_CANDIDATE_FOCUS_PREVIOUS = (32 << 8),
    VKEY_CANDIDATE_FOCUS_NEXT = (33 << 8),
    VKEY_CANDIDATE_RESET = (34 << 8),

    VKEY_PAGE_PREVIOUS = (40 << 8),
    VKEY_PAGE_NEXT = (41 << 8),
@@ -78,10 +80,11 @@ public:
    class Observer {
    public:
        virtual ~Observer () { }
        virtual void commitText (const std::string &commit_text) = 0;
        virtual void preeditTextChanged () = 0;
        virtual void auxiliaryTextChanged () = 0;
        virtual void lookupTableChanged () = 0;
        virtual void commitText (const InputContext * context,
                                 const std::string &commit_text) = 0;
        virtual void preeditTextChanged (const InputContext * context) = 0;
        virtual void auxiliaryTextChanged (const InputContext * context) = 0;
        virtual void lookupTableChanged (const InputContext * context) = 0;
    };

    enum InputType {
+23 −1
Original line number Diff line number Diff line
@@ -107,6 +107,10 @@ PhoneticContext::processKeyEvent (unsigned short key)
            return selectCandidateInPage (key_num);
        case VKEY_CANDIDATE_FOCUS:
            return focusCandidateInPage (key_num);
        case VKEY_CANDIDATE_FOCUS_PREVIOUS:
            return focusCandidatePrevious ();
        case VKEY_CANDIDATE_FOCUS_NEXT:
            return focusCandidateNext ();
        case VKEY_CANDIDATE_RESET:
            return resetCandidateInPage (key_num);

@@ -196,7 +200,7 @@ PhoneticContext::updateLookupTable (void)
        m_candidates.push_back (candidate);
    }

    m_observer->lookupTableChanged ();
    m_observer->lookupTableChanged (this);
}

void
@@ -220,6 +224,24 @@ PhoneticContext::focusCandidateInPage (guint i)
    return focusCandidate (page () * m_config.pageSize () + i);
}

gboolean
PhoneticContext::focusCandidatePrevious ()
{
    if (G_UNLIKELY (m_focused_candidate == 0)) {
        return FALSE;
    }
    return focusCandidate (m_focused_candidate - 1);
}

gboolean
PhoneticContext::focusCandidateNext ()
{
    if (G_UNLIKELY (m_focused_candidate >= m_candidates.size ())) {
        return FALSE;
    }
    return focusCandidate (m_focused_candidate + 1);
}

gboolean
PhoneticContext::focusCandidate (guint i)
{
+3 −1
Original line number Diff line number Diff line
@@ -77,6 +77,8 @@ protected:
    gboolean resetCandidateInPage (guint i);
    gboolean focusCandidate (guint i);
    gboolean focusCandidateInPage (guint i);
    gboolean focusCandidatePrevious ();
    gboolean focusCandidateNext ();

    virtual void selectPage (guint i);

+5 −5
Original line number Diff line number Diff line
@@ -62,7 +62,7 @@ PinyinContext::commit ()
    m_phrase_editor.commit ();
    reset ();
    update ();
    m_observer->commitText (m_buffer);
    m_observer->commitText (this, m_buffer);
}

void
@@ -71,7 +71,7 @@ PinyinContext::updatePreeditText ()
    /* preedit text = selected phrases + highlight candidate + rest text */
    if (G_UNLIKELY (m_phrase_editor.empty () && m_text.empty ())) {
        m_preedit_text.clear ();
        m_observer->preeditTextChanged ();
        m_observer->preeditTextChanged (this);
        return;
    }

@@ -148,7 +148,7 @@ PinyinContext::updatePreeditText ()
        m_preedit_text.rest_text = m_buffer.substr (edit_end_byte);
    }

    m_observer->preeditTextChanged ();
    m_observer->preeditTextChanged (this);
}

void
@@ -158,7 +158,7 @@ PinyinContext::updateAuxiliaryText (void)
    if (G_UNLIKELY (m_text.empty () ||
        m_candidates.size () == 0)) {
        m_auxiliary_text = "";
        m_observer->auxiliaryTextChanged ();
        m_observer->auxiliaryTextChanged (this);
        return;
    }

@@ -201,7 +201,7 @@ PinyinContext::updateAuxiliaryText (void)
    }
  
    m_auxiliary_text = m_buffer;
    m_observer->auxiliaryTextChanged ();
    m_observer->auxiliaryTextChanged (this);
}

};  // namespace PyZy
Loading