summaryrefslogtreecommitdiffstats
path: root/src/ZYZUserSymbolListAllSection.cc
diff options
context:
space:
mode:
authorPeng Wu <alexepico@gmail.com>2014-09-23 14:13:51 +0800
committerPeng Wu <alexepico@gmail.com>2014-09-23 14:13:51 +0800
commita7bb6ec0493aa97f8f03ab22d5831794234b6a4f (patch)
tree79e17bf0ef9ca3b4d841905a0020599705ac93e3 /src/ZYZUserSymbolListAllSection.cc
parent239be6e233e41790759a3e8894f9986074336b21 (diff)
downloadibus-libzhuyin-a7bb6ec0493aa97f8f03ab22d5831794234b6a4f.tar.gz
ibus-libzhuyin-a7bb6ec0493aa97f8f03ab22d5831794234b6a4f.tar.xz
ibus-libzhuyin-a7bb6ec0493aa97f8f03ab22d5831794234b6a4f.zip
write class UserSymbolListAllSection
Diffstat (limited to 'src/ZYZUserSymbolListAllSection.cc')
-rw-r--r--src/ZYZUserSymbolListAllSection.cc59
1 files changed, 59 insertions, 0 deletions
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 ();
+}
+
};