From b68d95fb69b043cfbb7319c308a040b5692749db Mon Sep 17 00:00:00 2001 From: Peng Wu Date: Tue, 1 Jul 2014 15:32:27 +0800 Subject: write ZYZBopomofoSymbolSection.cc --- src/Makefile.am | 2 ++ src/ZYZBopomofoSymbolSection.cc | 72 +++++++++++++++++++++++++++++++++++++++++ src/ZYZBuiltinSymbolSection.cc | 2 +- 3 files changed, 75 insertions(+), 1 deletion(-) diff --git a/src/Makefile.am b/src/Makefile.am index a8534ff..b8e9fcb 100644 --- a/src/Makefile.am +++ b/src/Makefile.am @@ -42,6 +42,7 @@ ibus_engine_libzhuyin_c_sources = \ ZYSymbols.cc \ ZYZBuiltinSymbolSection.cc \ ZYZPhoneticSection.cc \ + ZYZBopomofoSymbolSection.cc \ ZYFallbackEditor.cc \ ZYEngine.cc \ ZYZZhuyinEngine.cc \ @@ -67,6 +68,7 @@ ibus_engine_libzhuyin_h_sources = \ ZYZSymbolSection.h \ ZYZBuiltinSymbolSection.h \ ZYZPhoneticSection.h \ + ZYZBopomofoSymbolSection.h \ ZYPointer.h \ ZYProperty.h \ ZYRawEditor.h \ diff --git a/src/ZYZBopomofoSymbolSection.cc b/src/ZYZBopomofoSymbolSection.cc index acb91fd..4e9db8c 100644 --- a/src/ZYZBopomofoSymbolSection.cc +++ b/src/ZYZBopomofoSymbolSection.cc @@ -19,3 +19,75 @@ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. */ +#include "ZYZBopomofoSymbolSection.h" +#include +#include + +namespace ZY { + +BopomofoSymbolSection::BopomofoSymbolSection (PhoneticEditor & editor, + ZhuyinProperties & props) : + SymbolSection (editor, props) +{ + m_type = "bopomofo"; +} + +BopomofoSymbolSection::~BopomofoSymbolSection () +{ +} + +bool +BopomofoSymbolSection::initCandidates (const String & lookup) +{ + assert (1 == lookup.length ()); + m_lookup = lookup; + const char key = lookup[0]; + + /* cache the choices. */ + gchar ** symbols = NULL; + assert (zhuyin_in_chewing_keyboard (instance, key, &symbols)); + size_t num = g_strv_length (symbols); + assert (num > 0); + for (size_t i = 0; i < num; ++i) { + m_candidates.push_back (symbols[i]); + } + g_strfreev (symbols); + + return true; +} + +bool +BopomofoSymbolSection::fillLookupTableByPage () +{ + LookupTable & lookup_table = getLookupTable (); + + guint len = m_candidates.size (); + + guint filled_nr = lookup_table.size (); + guint page_size = lookup_table.pageSize (); + + /* fill lookup table by libzhuyin get candidates. */ + guint need_nr = MIN (page_size, len - filled_nr); + g_assert (need_nr >=0); + if (need_nr == 0) + return FALSE; + + for (guint i = filled_nr; i < filled_nr + need_nr; i++) { + if (i >= len) /* no more candidates */ + break; + + Text text (m_candidates[i]); + lookup_table.appendCandidate (text); + } + + return TRUE; +} + +int +BopomofoSymbolSection::selectCandidate (guint index) +{ + m_choice = m_candidates[index]; + return g_utf8_strlen (m_choice, -1);; +} + +}; diff --git a/src/ZYZBuiltinSymbolSection.cc b/src/ZYZBuiltinSymbolSection.cc index 5576187..9309c1c 100644 --- a/src/ZYZBuiltinSymbolSection.cc +++ b/src/ZYZBuiltinSymbolSection.cc @@ -84,7 +84,7 @@ int BuiltinSymbolSection::selectCandidate (guint index) { m_choice = m_candidates[index]; - return 1; + return g_utf8_strlen (m_choice, -1); } }; -- cgit