diff options
author | Peng Wu <alexepico@gmail.com> | 2014-09-23 14:13:51 +0800 |
---|---|---|
committer | Peng Wu <alexepico@gmail.com> | 2014-09-23 14:13:51 +0800 |
commit | a7bb6ec0493aa97f8f03ab22d5831794234b6a4f (patch) | |
tree | 79e17bf0ef9ca3b4d841905a0020599705ac93e3 /src | |
parent | 239be6e233e41790759a3e8894f9986074336b21 (diff) | |
download | ibus-libzhuyin-a7bb6ec0493aa97f8f03ab22d5831794234b6a4f.tar.gz ibus-libzhuyin-a7bb6ec0493aa97f8f03ab22d5831794234b6a4f.tar.xz ibus-libzhuyin-a7bb6ec0493aa97f8f03ab22d5831794234b6a4f.zip |
write class UserSymbolListAllSection
Diffstat (limited to 'src')
-rw-r--r-- | src/Makefile.am | 2 | ||||
-rw-r--r-- | src/ZYZUserSymbolListAllSection.cc | 59 | ||||
-rw-r--r-- | src/ZYZUserSymbolListAllSection.h | 2 |
3 files changed, 62 insertions, 1 deletions
diff --git a/src/Makefile.am b/src/Makefile.am index c58ff0d..5c987f5 100644 --- a/src/Makefile.am +++ b/src/Makefile.am @@ -44,6 +44,7 @@ ibus_engine_libzhuyin_c_sources = \ ZYZBuiltinSymbolSection.cc \ ZYZPhoneticSection.cc \ ZYZBopomofoSymbolSection.cc \ + ZYZUserSymbolListAllSection.cc \ ZYFallbackEditor.cc \ ZYEngine.cc \ ZYZZhuyinEngine.cc \ @@ -71,6 +72,7 @@ ibus_engine_libzhuyin_h_sources = \ ZYZBuiltinSymbolSection.h \ ZYZPhoneticSection.h \ ZYZBopomofoSymbolSection.h \ + ZYZUserSymbolListAllSection.h \ ZYPointer.h \ ZYProperty.h \ ZYRawEditor.h \ diff --git a/src/ZYZUserSymbolListAllSection.cc b/src/ZYZUserSymbolListAllSection.cc index af67962..5437d2d 100644 --- a/src/ZYZUserSymbolListAllSection.cc +++ b/src/ZYZUserSymbolListAllSection.cc @@ -49,8 +49,67 @@ UserSymbolListAllSection::~UserSymbolListAllSection () gboolean UserSymbolListAllSection::loadUserSymbolFile (const gchar * filename) { + printf ("load %s.\n", filename); gboolean retval = m_user_symbols.loadFromFile (filename); return retval; } +bool +UserSymbolListAllSection::initCandidates (zhuyin_instance_t * instance, + const String & lookup) +{ + if (!lookup) + return false; + + m_candidates.clear (); + + assert ("`" == lookup); + m_lookup = lookup; + + /* cache the symbols. */ + const std::vector<String> & indexes = m_user_symbols.getIndexes (); + for (size_t i = 0; i < indexes.size (); ++i) { + m_candidates.push_back (indexes[i]); + } + + return true; +} + +bool +UserSymbolListAllSection::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 +UserSymbolListAllSection::selectCandidate (guint index) +{ + if (index >= m_candidates.size ()) + return 0; + + m_choice = m_candidates[index]; + return m_choice.utf8Length (); +} + }; diff --git a/src/ZYZUserSymbolListAllSection.h b/src/ZYZUserSymbolListAllSection.h index 9b7bec4..2c728b4 100644 --- a/src/ZYZUserSymbolListAllSection.h +++ b/src/ZYZUserSymbolListAllSection.h @@ -49,7 +49,7 @@ protected: std::vector<String> m_candidates; SymbolLookup m_user_symbols; -} +}; }; |