From fdf8943c8a0745f208e715e96d4dd6162e9e7e81 Mon Sep 17 00:00:00 2001 From: Peng Huang Date: Tue, 13 Apr 2010 15:54:57 +0800 Subject: [PATCH] Enable special phrases in double pinyin --- src/DoublePinyinEditor.cc | 110 ++++++++++++++++++++++++++++++++-------------- src/FullPinyinEditor.cc | 17 ------- src/PinyinEditor.cc | 81 ---------------------------------- src/PinyinEditor.h | 2 - 4 files changed, 78 insertions(+), 132 deletions(-) diff --git a/src/DoublePinyinEditor.cc b/src/DoublePinyinEditor.cc index decfe7f..7280bb5 100644 --- a/src/DoublePinyinEditor.cc +++ b/src/DoublePinyinEditor.cc @@ -53,12 +53,18 @@ DoublePinyinEditor::insert (gint ch) return FALSE; } else { - updatePreeditText (); - updateAuxiliaryText (); + if (updateSpecialPhrases ()) { + update (); + } + else { + updatePreeditText (); + updateAuxiliaryText (); + } return TRUE; } } else { + updateSpecialPhrases (); updatePhraseEditor (); update (); return TRUE; @@ -75,12 +81,18 @@ DoublePinyinEditor::removeCharBefore (void) m_text.erase (m_cursor, 1); if (updatePinyin (FALSE)) { + updateSpecialPhrases (); updatePhraseEditor (); update (); } else { - updatePreeditText (); - updateAuxiliaryText (); + if (updateSpecialPhrases ()) { + update (); + } + else { + updatePreeditText (); + updateAuxiliaryText (); + } } return TRUE; } @@ -92,8 +104,13 @@ DoublePinyinEditor::removeCharAfter (void) return FALSE; m_text.erase (m_cursor, 1); - updatePreeditText (); - updateAuxiliaryText (); + if (updateSpecialPhrases ()) { + update (); + } + else { + updatePreeditText (); + updateAuxiliaryText (); + } return TRUE; } @@ -106,14 +123,20 @@ DoublePinyinEditor::removeWordBefore (void) if (G_UNLIKELY (m_cursor > m_pinyin_len)) { m_text.erase (m_pinyin_len, m_cursor - m_pinyin_len); m_cursor = m_pinyin_len; - updatePreeditText (); - updateAuxiliaryText (); + if (updateSpecialPhrases ()) { + update (); + } + else { + updatePreeditText (); + updateAuxiliaryText (); + } } else { m_pinyin_len = m_pinyin.back ().begin; m_pinyin.pop_back (); m_text.erase (m_pinyin_len, m_cursor - m_pinyin_len); m_cursor = m_pinyin_len; + updateSpecialPhrases (); updatePhraseEditor (); update (); } @@ -128,8 +151,13 @@ DoublePinyinEditor::removeWordAfter (void) return FALSE; m_text.erase (m_cursor); - updatePreeditText (); - updateAuxiliaryText (); + if (updateSpecialPhrases ()) { + update (); + } + else { + updatePreeditText (); + updateAuxiliaryText (); + } return TRUE; } @@ -142,17 +170,28 @@ DoublePinyinEditor::moveCursorLeft (void) m_cursor --; if (m_cursor >= m_pinyin_len) { - updatePreeditText (); - updateAuxiliaryText (); + if (updateSpecialPhrases ()) { + update (); + } + else { + updatePreeditText (); + updateAuxiliaryText (); + } } else { if (updatePinyin (FALSE)) { + updateSpecialPhrases (); updatePhraseEditor (); update (); } else { - updatePreeditText (); - updateAuxiliaryText (); + if (updateSpecialPhrases ()) { + update (); + } + else { + updatePreeditText (); + updateAuxiliaryText (); + } } } @@ -167,12 +206,18 @@ DoublePinyinEditor::moveCursorRight (void) m_cursor ++; if (updatePinyin (FALSE)) { + updateSpecialPhrases (); updatePhraseEditor (); update (); } else { - updatePreeditText (); - updateAuxiliaryText (); + if (updateSpecialPhrases ()) { + update (); + } + else { + updatePreeditText (); + updateAuxiliaryText (); + } } return TRUE; } @@ -185,12 +230,18 @@ DoublePinyinEditor::moveCursorLeftByWord (void) if (G_UNLIKELY (m_cursor > m_pinyin_len)) { m_cursor = m_pinyin_len; - updatePreeditText (); - updateAuxiliaryText (); + if (updateSpecialPhrases ()) { + update (); + } + else { + updatePreeditText (); + updateAuxiliaryText (); + } } else { m_cursor = m_pinyin_len = m_pinyin.back ().begin; m_pinyin.pop_back (); + updateSpecialPhrases (); updatePhraseEditor (); update (); } @@ -213,6 +264,7 @@ DoublePinyinEditor::moveCursorToBegin (void) m_cursor = 0; m_pinyin.clear (); m_pinyin_len = 0; + updateSpecialPhrases (); updatePhraseEditor (); update (); @@ -227,12 +279,18 @@ DoublePinyinEditor::moveCursorToEnd (void) m_cursor = m_text.length (); if (updatePinyin (FALSE)) { + updateSpecialPhrases (); updatePhraseEditor (); update (); } else { - updatePreeditText (); - updateAuxiliaryText (); + if (updateSpecialPhrases ()) { + update (); + } + else { + updatePreeditText (); + updateAuxiliaryText (); + } } return TRUE; } @@ -241,18 +299,6 @@ void DoublePinyinEditor::reset (void) { PinyinEditor::reset (); -#if 0 - if (m_cursor != 0 || - m_text.empty () == FALSE || - m_pinyin.empty () == FALSE) { - m_cursor = 0; - m_text.truncate (0); - m_pinyin.clear (); - m_pinyin_len = 0; - updatePhraseEditor (); - update (); - } -#endif } inline const Pinyin * diff --git a/src/FullPinyinEditor.cc b/src/FullPinyinEditor.cc index 38af6b5..432dc0b 100644 --- a/src/FullPinyinEditor.cc +++ b/src/FullPinyinEditor.cc @@ -16,23 +16,6 @@ void FullPinyinEditor::reset (void) { PinyinEditor::reset (); -#if 0 - gboolean retval = FALSE; - if (m_cursor != 0) { - m_cursor = 0; - retval = TRUE; - } - - if (m_text.length () != 0) { - m_text.truncate (0); - retval = TRUE; - } - - if (retval) { - updateSpecialPhrases (); - updatePinyin (); - } -#endif } gboolean diff --git a/src/PinyinEditor.cc b/src/PinyinEditor.cc index dc6543d..51caa59 100644 --- a/src/PinyinEditor.cc +++ b/src/PinyinEditor.cc @@ -333,19 +333,6 @@ PinyinEditor::updatePreeditText (void) return; } - updatePreeditTextInTypingMode (); - return; -#if 0 - if (m_cursor == m_text.size () || 1) - updatePreeditTextInTypingMode (); - else - updatePreeditTextInEditingMode (); -#endif -} - -inline void -PinyinEditor::updatePreeditTextInTypingMode (void) -{ guint edit_begin = 0; guint edit_end = 0; @@ -417,74 +404,6 @@ PinyinEditor::updatePreeditTextInTypingMode (void) Editor::updatePreeditText (preedit_text, edit_begin, TRUE); } -inline void -PinyinEditor::updatePreeditTextInEditingMode (void) -{ - m_buffer.clear (); - - /* add select phrases */ - m_buffer << m_phrase_editor.selectedString (); - - /* add selected special phrase */ - m_buffer << m_selected_special_phrase; - - /* add highlight candidate */ - const PinyinArray & pinyin = m_phrase_editor.pinyin (); - guint candidate_begin = m_buffer.utf8Length (); - guint candidate_length = 0; - guint candidate_pinyin_end = 0; - - if (m_lookup_table.size () > 0) { - guint cursor = m_lookup_table.cursorPos (); - if (cursor < m_special_phrases.size ()) { - /* highligh candidates is a special phrase */ - m_buffer << m_text.substr (m_phrase_editor.cursorInChar (), - m_cursor - m_phrase_editor.cursorInChar ()); - } - else { - /* highligh candidates is a normail phrase */ - cursor -= m_special_phrases.size (); - const Phrase & candidate = m_phrase_editor.candidate (cursor); - candidate_length = candidate.len; - - m_buffer << pinyin[candidate_begin]->sheng << pinyin[candidate_begin]->yun; - - for (guint i = 1; i < candidate_length; i++) { - m_buffer << ' ' << pinyin[candidate_begin + i]->sheng << pinyin[candidate_begin + i]->yun; - } - } - candidate_pinyin_end = m_buffer.utf8Length (); - } - - /* add rest text */ - if (candidate_begin + candidate_length < pinyin.size ()) { - if (m_buffer) - m_buffer << ' ' ; - m_buffer << textAfterPinyin (candidate_begin + candidate_length); - } - else { - const gchar * p = textAfterPinyin (); - if (*p != '\0') { - if (m_buffer) - m_buffer << ' '; - m_buffer << p; - } - } - - StaticText preedit_text (m_buffer); - /* underline */ - preedit_text.appendAttribute (IBUS_ATTR_TYPE_UNDERLINE, IBUS_ATTR_UNDERLINE_SINGLE, 0, -1); - - /* candidate */ - if (candidate_length != 0) { - preedit_text.appendAttribute (IBUS_ATTR_TYPE_FOREGROUND, 0x00000000, - candidate_begin, candidate_pinyin_end); - preedit_text.appendAttribute (IBUS_ATTR_TYPE_BACKGROUND, 0x00c8c8f0, - candidate_begin, candidate_pinyin_end); - } - Editor::updatePreeditText (preedit_text, candidate_begin, TRUE); -} - void PinyinEditor::updateAuxiliaryText (void) { diff --git a/src/PinyinEditor.h b/src/PinyinEditor.h index bfccfbf..b929bf7 100644 --- a/src/PinyinEditor.h +++ b/src/PinyinEditor.h @@ -40,8 +40,6 @@ protected: gboolean processOthers (guint keyval, guint keycode, guint modifiers); void updatePreeditText (void); - void updatePreeditTextInTypingMode (void); - void updatePreeditTextInEditingMode (void); void updateAuxiliaryText (void); void updateLookupTable (void); gboolean fillLookupTableByPage (void); -- 2.7.4