summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorPeng Wu <alexepico@gmail.com>2014-07-02 17:12:40 +0800
committerPeng Wu <alexepico@gmail.com>2014-07-02 17:12:40 +0800
commitcde4b45e75e2cf7bcf2b22ab8056322b1ad04cba (patch)
treea425fa5e801a62681f34966068545d4fca99b38d
parent19e5caec8ff73a7b8e3307a490ec5930706633aa (diff)
downloadibus-libzhuyin-cde4b45e75e2cf7bcf2b22ab8056322b1ad04cba.tar.gz
ibus-libzhuyin-cde4b45e75e2cf7bcf2b22ab8056322b1ad04cba.tar.xz
ibus-libzhuyin-cde4b45e75e2cf7bcf2b22ab8056322b1ad04cba.zip
write method prepareCandidates
-rw-r--r--src/ZYSymbols.h2
-rw-r--r--src/ZYZBopomofoSymbolSection.cc3
-rw-r--r--src/ZYZBuiltinSymbolSection.cc2
-rw-r--r--src/ZYZPhoneticEditor.cc119
-rw-r--r--src/ZYZPhoneticEditor.h1
5 files changed, 123 insertions, 4 deletions
diff --git a/src/ZYSymbols.h b/src/ZYSymbols.h
index a6421b9..47ea6d2 100644
--- a/src/ZYSymbols.h
+++ b/src/ZYSymbols.h
@@ -49,6 +49,8 @@ bool
half_english_to_full_english (const char key, String & english);
#define BUILTIN_SYMBOL_TYPE "builtin"
+#define BOPOMOFO_SYMBOL_TYPE "bopomofo"
+
};
diff --git a/src/ZYZBopomofoSymbolSection.cc b/src/ZYZBopomofoSymbolSection.cc
index c8e5716..7ccf5f6 100644
--- a/src/ZYZBopomofoSymbolSection.cc
+++ b/src/ZYZBopomofoSymbolSection.cc
@@ -22,6 +22,7 @@
#include "ZYZBopomofoSymbolSection.h"
#include <assert.h>
#include <zhuyin.h>
+#include "ZYSymbols.h"
namespace ZY {
@@ -29,7 +30,7 @@ BopomofoSymbolSection::BopomofoSymbolSection (PhoneticEditor & editor,
ZhuyinProperties & props) :
SymbolSection (editor, props)
{
- m_type = "bopomofo";
+ m_type = BOPOMOFO_SYMBOL_TYPE;
}
BopomofoSymbolSection::~BopomofoSymbolSection ()
diff --git a/src/ZYZBuiltinSymbolSection.cc b/src/ZYZBuiltinSymbolSection.cc
index fb4956b..275739c 100644
--- a/src/ZYZBuiltinSymbolSection.cc
+++ b/src/ZYZBuiltinSymbolSection.cc
@@ -29,7 +29,7 @@ BuiltinSymbolSection::BuiltinSymbolSection (PhoneticEditor & editor,
ZhuyinProperties & props) :
SymbolSection (editor, props)
{
- m_type = "builtin";
+ m_type = BUILTIN_SYMBOL_TYPE;
}
BuiltinSymbolSection::~BuiltinSymbolSection ()
diff --git a/src/ZYZPhoneticEditor.cc b/src/ZYZPhoneticEditor.cc
index b670614..5e2a7df 100644
--- a/src/ZYZPhoneticEditor.cc
+++ b/src/ZYZPhoneticEditor.cc
@@ -169,8 +169,8 @@ PhoneticEditor::processShowCandidateKey (guint keyval, guint keycode,
switch (keyval) {
case IBUS_Down:
case IBUS_KP_Down:
- assert (FALSE);
/* check phonetic or symbol section here */
+ prepareCandidates ();
m_input_state = STATE_CANDIDATE_SHOWN;
break;
@@ -499,7 +499,8 @@ PhoneticEditor::resizeInstances (void)
}
}
-guint PhoneticEditor::getZhuyinCursor (void)
+guint
+PhoneticEditor::getZhuyinCursor (void)
{
/* decrement the cursor variable to calculate the zhuyin cursor. */
guint cursor = m_cursor;
@@ -638,4 +639,118 @@ PhoneticEditor::insertEnglish (gint ch)
return FALSE;
}
+gboolean
+PhoneticEditor::prepareCandidates (void)
+{
+ /* decrement the cursor variable to calculate the zhuyin cursor. */
+ guint cursor = m_cursor;
+
+ const String & enhanced_text = m_text;
+
+ size_t index = 0;
+ size_t start_pos = 0, end_pos = 0;
+
+ while (end_pos != enhanced_text.size ()) {
+ if (0 == cursor)
+ break;
+
+ start_pos = end_pos;
+ section_t type = probe_section_quick (enhanced_text, start_pos);
+
+ if (PHONETIC_SECTION == type) {
+ String section;
+ get_phonetic_section (enhanced_text, start_pos, end_pos, section);
+
+ size_t section_len = end_pos - start_pos;
+
+ if (cursor < section_len)
+ break;
+
+ cursor -= section_len;
+ ++index;
+ }
+
+ if (SYMBOL_SECTION == type) {
+ String type, lookup, choice;
+ get_symbol_section (enhanced_text, start_pos, end_pos,
+ type, lookup, choice);
+ --cursor;
+ }
+ }
+
+ /* deal with candidates */
+ if (m_cursor != enhanced_text.size ()) {
+ section_t type = probe_section_quick (enhanced_text, start_pos);
+
+ if (PHONETIC_SECTION == type) {
+ String section;
+ get_phonetic_section (enhanced_text, start_pos, end_pos, section);
+ size_t section_len = end_pos - start_pos;
+
+ zhuyin_instance_t * instance = m_instances[index];
+ size_t parsed_len = zhuyin_get_parsed_input_length (instance);
+
+ assert (cursor < section_len);
+ assert (parsed_len <= section_len);
+
+ String lookup;
+ if (cursor >= parsed_len) {
+ lookup = section[cursor];
+ m_input_state = STATE_BOPOMOFO_SYMBOL_SHOWN;
+ m_symbol_sections[m_input_state]->initCandidates
+ (m_instance, lookup);
+
+ update ();
+ return TRUE;
+ } else {
+ guint len = 0;
+ zhuyin_get_n_zhuyin (instance, &len);
+
+ guint inner_cursor = len;
+
+ guint16 prev_end = 0, cur_end;
+ for (size_t i = 0; i < len; ++i) {
+ ChewingKeyRest *pos = NULL;
+ zhuyin_get_zhuyin_key_rest (instance, i, &pos);
+ zhuyin_get_zhuyin_key_rest_positions
+ (instance, pos, NULL, &cur_end);
+
+ if (prev_end < cursor && cursor < cur_end)
+ inner_cursor = i;
+
+ prev_end = cur_end;
+ }
+
+ assert (inner_cursor >= 0);
+ m_input_state = STATE_CANDIDATE_SHOWN;
+ m_phonetic_section->initCandidates (instance, inner_cursor);
+
+ update ();
+ return TRUE;
+ }
+ }
+
+ if (SYMBOL_SECTION == type) {
+ String type, lookup, choice;
+ get_symbol_section (enhanced_text, start_pos, end_pos,
+ type, lookup, choice);
+
+ if (BUILTIN_SYMBOL_TYPE == type) {
+ m_input_state = STATE_BUILTIN_SYMBOL_SHOWN;
+ m_symbol_sections[m_input_state]->initCandidates
+ (m_instance, lookup);
+ } else if (BOPOMOFO_SYMBOL_TYPE == type) {
+ m_input_state = STATE_BOPOMOFO_SYMBOL_SHOWN;
+ m_symbol_sections[m_input_state]->initCandidates
+ (m_instance, lookup);
+ } else
+ assert (FALSE);
+
+ update ();
+ return TRUE;
+ }
+ }
+}
+
+
};
diff --git a/src/ZYZPhoneticEditor.h b/src/ZYZPhoneticEditor.h
index 6652ac6..7ea3a58 100644
--- a/src/ZYZPhoneticEditor.h
+++ b/src/ZYZPhoneticEditor.h
@@ -68,6 +68,7 @@ public:
virtual gboolean insertEnglish (gint ch);
protected:
+ gboolean prepareCandidates (void);
gboolean selectCandidate (guint i);
gboolean selectCandidateInPage (guint i);