From 99d50b6e284609e90bade4ef6b754f5cdba9653e Mon Sep 17 00:00:00 2001 From: Peng Wu Date: Fri, 30 May 2014 19:48:55 +0800 Subject: write class ZhuyinEditor in progress --- src/ZYZPhoneticEditor.cc | 4 ++++ src/ZYZPhoneticEditor.h | 2 +- src/ZYZZhuyinEditor.cc | 52 ++++++++++++++++++++++++++++++++++++++++++++++++ src/ZYZZhuyinEditor.h | 2 +- 4 files changed, 58 insertions(+), 2 deletions(-) diff --git a/src/ZYZPhoneticEditor.cc b/src/ZYZPhoneticEditor.cc index 3eadaf4..e788836 100644 --- a/src/ZYZPhoneticEditor.cc +++ b/src/ZYZPhoneticEditor.cc @@ -74,6 +74,10 @@ PhoneticEditor::processEnter (guint keyval, guint keycode, { if (!m_text) return FALSE; + + if (IBUS_Return != keyval && IBUS_KP_Enter != keyval) + return FALSE; + if (cmshm_filter (modifiers) != 0) return TRUE; diff --git a/src/ZYZPhoneticEditor.h b/src/ZYZPhoneticEditor.h index 12eecae..0a8283f 100644 --- a/src/ZYZPhoneticEditor.h +++ b/src/ZYZPhoneticEditor.h @@ -94,7 +94,7 @@ protected: /* use libzhuyin here. */ zhuyin_instance_t *m_instance; - enum { + enum InputState { STATE_INPUT = 0, // input state STATE_CANDIDATE_SHOWN, // candidates shown state STATE_BUILTIN_SYMBOL_SHOWN, // built-in symbol shown state diff --git a/src/ZYZZhuyinEditor.cc b/src/ZYZZhuyinEditor.cc index 20671c8..05e704c 100644 --- a/src/ZYZZhuyinEditor.cc +++ b/src/ZYZZhuyinEditor.cc @@ -171,3 +171,55 @@ ZhuyinEditor::updatePreeditText (void) Editor::updatePreeditText (preedit_text, cursor, TRUE); return; } + +gboolean +ZhuyinEditor::insert (gint ch) +{ + gchar ** symbols = NULL; + if (zhuyin_in_chewing_keyboard (m_instance, ch, &symbols)) { + g_strfreev (symbols); + + insert_phonetic (m_text, m_cursor++, ch); + + updateZhuyin (); + update (); + return TRUE; + } + + /* TODO:: handle symbols here. */ + + return FALSE; +} + +gboolean +ZhuyinEditor::processKeyEvent (guint keyval, guint keycode, guint modifiers) +{ + modifiers &= (IBUS_SHIFT_MASK | + IBUS_CONTROL_MASK | + IBUS_MOD1_MASK | + IBUS_SUPER_MASK | + IBUS_HYPER_MASK | + IBUS_META_MASK | + IBUS_LOCK_MASK); + + if (STATE_INPUT == m_input_state) { + if (insert (keyval)) + return TRUE; + + if (processEnter (keyval, keycode, modifiers)) + return TRUE; + + if (processFunctionKey (keyval, keycode, modifiers)) + return TRUE; + } + + if (STATE_CANDIDATE_SHOWN == m_input_state || + STATE_BUILTIN_SYMBOL_SHOWN == m_input_state /* || + STATE_USER_SYMBOL_LIST_ALL == m_input_state || + STATE_USER_SYMBOL_SHOWN == m_input_state */) { + if (processCandidateKey (keyval, keycode, modifiers)) + return TRUE; + } + + return FALSE; +} diff --git a/src/ZYZZhuyinEditor.h b/src/ZYZZhuyinEditor.h index 4ede0ed..bbe4b39 100644 --- a/src/ZYZZhuyinEditor.h +++ b/src/ZYZZhuyinEditor.h @@ -29,13 +29,13 @@ namespace ZY { class Config; class ZhuyinEditor : public PhoneticEditor { + using PhoneticEditor::InputState; public: ZhuyinEditor (ZhuyinProperties & props, Config & config); virtual ~ZhuyinEditor (void); protected: - gboolean processZhuyin (guint keyval, guint keycode, guint modifiers); gboolean processKeyEvent (guint keyval, guint keycode, guint modifiers); virtual void updatePreeditText (); -- cgit