summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorPeng Wu <alexepico@gmail.com>2014-09-25 10:59:27 +0800
committerPeng Wu <alexepico@gmail.com>2014-09-25 11:12:35 +0800
commitae3662e847b115dabb2f1f80676d5f19286eae0d (patch)
tree6ffc44a1f0d25223963b34c8349b5aabdcbbf2b2
parent7fc48a9c22074726e7250e756e7af69f6a6691d5 (diff)
downloadibus-libzhuyin-ae3662e847b115dabb2f1f80676d5f19286eae0d.tar.gz
ibus-libzhuyin-ae3662e847b115dabb2f1f80676d5f19286eae0d.tar.xz
ibus-libzhuyin-ae3662e847b115dabb2f1f80676d5f19286eae0d.zip
support user symbols
-rw-r--r--src/ZYZPhoneticEditor.cc73
-rw-r--r--src/ZYZPhoneticEditor.h3
-rw-r--r--src/ZYZPinyinEditor.cc7
-rw-r--r--src/ZYZZhuyinEditor.cc7
4 files changed, 79 insertions, 11 deletions
diff --git a/src/ZYZPhoneticEditor.cc b/src/ZYZPhoneticEditor.cc
index 6252aa1..dd520c9 100644
--- a/src/ZYZPhoneticEditor.cc
+++ b/src/ZYZPhoneticEditor.cc
@@ -29,6 +29,8 @@
#include "ZYEnhancedText.h"
#include "ZYLibZhuyin.h"
#include "ZYSymbols.h"
+#include "ZYZUserSymbolListAllSection.h"
+#include "ZYZUserSymbolShownSection.h"
namespace ZY {
@@ -59,6 +61,12 @@ PhoneticEditor::PhoneticEditor (ZhuyinProperties & props, Config & config)
m_symbol_sections[STATE_BOPOMOFO_SYMBOL_SHOWN].reset
(new BopomofoSymbolSection (*this, props));
+ m_symbol_sections[STATE_USER_SYMBOL_LIST_ALL].reset
+ (new UserSymbolListAllSection (*this, props));
+
+ m_symbol_sections[STATE_USER_SYMBOL_SHOWN].reset
+ (new UserSymbolShownSection (*this, props));
+
m_phonetic_section.reset
(new PhoneticSection (*this, props));
@@ -318,6 +326,25 @@ PhoneticEditor::processEasySymbolKey (guint keyval, guint keycode,
}
gboolean
+PhoneticEditor::processUserSymbolKey (guint keyval, guint keycode,
+ guint modifiers)
+{
+ if (!m_config.userSymbol ())
+ return FALSE;
+
+ if ('`' == keyval)
+ return FALSE;
+
+ m_input_state = STATE_USER_SYMBOL_LIST_ALL;
+ m_symbol_sections[m_input_state]->initCandidates
+ (m_instance, "`");
+
+ update ();
+ return TRUE;
+}
+
+
+gboolean
PhoneticEditor::processKeyEvent (guint keyval, guint keycode,
guint modifiers)
{
@@ -350,9 +377,9 @@ PhoneticEditor::fillLookupTableByPage (void)
return m_phonetic_section->fillLookupTableByPage ();
if (STATE_BUILTIN_SYMBOL_SHOWN == m_input_state ||
- STATE_BOPOMOFO_SYMBOL_SHOWN == m_input_state /* ||
+ STATE_BOPOMOFO_SYMBOL_SHOWN == m_input_state ||
STATE_USER_SYMBOL_LIST_ALL == m_input_state ||
- STATE_USER_SYMBOL_SHOWN == m_input_state */) {
+ STATE_USER_SYMBOL_SHOWN == m_input_state) {
return m_symbol_sections[m_input_state]->
fillLookupTableByPage ();
}
@@ -462,9 +489,7 @@ PhoneticEditor::selectCandidate (guint index)
}
if (STATE_BUILTIN_SYMBOL_SHOWN == m_input_state ||
- STATE_BOPOMOFO_SYMBOL_SHOWN == m_input_state /* ||
- STATE_USER_SYMBOL_LIST_ALL == m_input_state ||
- STATE_USER_SYMBOL_SHOWN == m_input_state */) {
+ STATE_BOPOMOFO_SYMBOL_SHOWN == m_input_state) {
SymbolSectionPtr symbols = m_symbol_sections[m_input_state];
int offset = symbols->selectCandidate (index);
@@ -483,6 +508,44 @@ PhoneticEditor::selectCandidate (guint index)
return TRUE;
}
+ if (STATE_USER_SYMBOL_LIST_ALL == m_input_state ||
+ STATE_USER_SYMBOL_SHOWN == m_input_state) {
+ SymbolSectionPtr symbols = m_symbol_sections[m_input_state];
+
+ int offset = symbols->selectCandidate (index);
+
+ if (0 == offset)
+ return FALSE;
+
+ if (1 == offset) { /* direct commit. */
+ String choice = symbols->m_choice;
+ String lookup;
+ int ch = find_lookup_key (choice);
+ if (ch != 0)
+ lookup = (gchar) ch;
+
+ assert (BUILTIN_SYMBOL_TYPE == symbols->m_type);
+ erase_input_sequence (m_text, m_cursor, 1);
+ insert_symbol (m_text, m_cursor, symbols->m_type,
+ lookup, choice);
+
+ m_cursor += offset;
+ m_input_state = STATE_INPUT;
+
+ update ();
+ return TRUE;
+ }
+
+ if (1 < offset) { /* show candidate. */
+ m_input_state = STATE_USER_SYMBOL_SHOWN;
+ m_symbol_sections[m_input_state]->initCandidates
+ (m_instance, symbols->m_choice);
+
+ update ();
+ return TRUE;
+ }
+ }
+
return FALSE;
}
diff --git a/src/ZYZPhoneticEditor.h b/src/ZYZPhoneticEditor.h
index 5e08587..8e42f79 100644
--- a/src/ZYZPhoneticEditor.h
+++ b/src/ZYZPhoneticEditor.h
@@ -64,6 +64,7 @@ public:
virtual gboolean processShowCandidateKey (guint keyval, guint keycode, guint modifiers);
virtual gboolean processCandidateKey (guint keyval, guint keycode, guint modifiers);
virtual gboolean processEasySymbolKey (guint keyval, guint keycode, guint modifiers);
+ virtual gboolean processUserSymbolKey (guint keyval, guint keycode, guint modifiers);
virtual void updateLookupTable ();
virtual void updateLookupTableFast ();
virtual gboolean fillLookupTableByPage ();
@@ -111,10 +112,8 @@ protected:
STATE_CANDIDATE_SHOWN, // candidates shown state
STATE_BUILTIN_SYMBOL_SHOWN, // built-in symbol shown state
STATE_BOPOMOFO_SYMBOL_SHOWN, // bopomofo symbol shown state
-#if 0
STATE_USER_SYMBOL_LIST_ALL, // user symbol input state
STATE_USER_SYMBOL_SHOWN, // user symbol shown state
-#endif
STATE_LAST,
} m_input_state;
diff --git a/src/ZYZPinyinEditor.cc b/src/ZYZPinyinEditor.cc
index a0c7a35..aac58c0 100644
--- a/src/ZYZPinyinEditor.cc
+++ b/src/ZYZPinyinEditor.cc
@@ -222,6 +222,9 @@ PinyinEditor::processKeyEvent (guint keyval, guint keycode, guint modifiers)
if (processEasySymbolKey (keyval, keycode, modifiers))
return TRUE;
+ if (processUserSymbolKey (keyval, keycode, modifiers))
+ return TRUE;
+
if (insert (keyval))
return TRUE;
@@ -237,9 +240,9 @@ PinyinEditor::processKeyEvent (guint keyval, guint keycode, guint modifiers)
if (STATE_CANDIDATE_SHOWN == m_input_state ||
STATE_BUILTIN_SYMBOL_SHOWN == m_input_state ||
- STATE_BOPOMOFO_SYMBOL_SHOWN == m_input_state /* ||
+ STATE_BOPOMOFO_SYMBOL_SHOWN == m_input_state ||
STATE_USER_SYMBOL_LIST_ALL == m_input_state ||
- STATE_USER_SYMBOL_SHOWN == m_input_state */) {
+ STATE_USER_SYMBOL_SHOWN == m_input_state) {
if (processSpace (keyval, keycode, modifiers))
return TRUE;
diff --git a/src/ZYZZhuyinEditor.cc b/src/ZYZZhuyinEditor.cc
index b32e1e1..f71b52e 100644
--- a/src/ZYZZhuyinEditor.cc
+++ b/src/ZYZZhuyinEditor.cc
@@ -230,6 +230,9 @@ ZhuyinEditor::processKeyEvent (guint keyval, guint keycode, guint modifiers)
if (processEasySymbolKey (keyval, keycode, modifiers))
return TRUE;
+ if (processUserSymbolKey (keyval, keycode, modifiers))
+ return TRUE;
+
if (insert (keyval))
return TRUE;
@@ -245,9 +248,9 @@ ZhuyinEditor::processKeyEvent (guint keyval, guint keycode, guint modifiers)
if (STATE_CANDIDATE_SHOWN == m_input_state ||
STATE_BUILTIN_SYMBOL_SHOWN == m_input_state ||
- STATE_BOPOMOFO_SYMBOL_SHOWN == m_input_state /* ||
+ STATE_BOPOMOFO_SYMBOL_SHOWN == m_input_state ||
STATE_USER_SYMBOL_LIST_ALL == m_input_state ||
- STATE_USER_SYMBOL_SHOWN == m_input_state */) {
+ STATE_USER_SYMBOL_SHOWN == m_input_state) {
if (processSpace (keyval, keycode, modifiers))
return TRUE;