summaryrefslogtreecommitdiffstats
path: root/src/PYPPinyinEditor.cc
diff options
context:
space:
mode:
authorPeng Wu <alexepico@gmail.com>2011-09-02 16:49:00 +0800
committerPeng Wu <alexepico@gmail.com>2011-12-22 12:23:11 +0800
commit9d7be99bc520bd98cf52fa88f947f3787e411fde (patch)
tree7b5f1f7057da332b2477110655af69c90daa26d9 /src/PYPPinyinEditor.cc
parentf8dca3a01a6f976fd41a13bb01dac6ab8134eb0f (diff)
downloadibus-libpinyin-9d7be99bc520bd98cf52fa88f947f3787e411fde.tar.gz
ibus-libpinyin-9d7be99bc520bd98cf52fa88f947f3787e411fde.tar.xz
ibus-libpinyin-9d7be99bc520bd98cf52fa88f947f3787e411fde.zip
begin to write pinyin editor
Diffstat (limited to 'src/PYPPinyinEditor.cc')
-rw-r--r--src/PYPPinyinEditor.cc202
1 files changed, 202 insertions, 0 deletions
diff --git a/src/PYPPinyinEditor.cc b/src/PYPPinyinEditor.cc
index a259a99..a78544d 100644
--- a/src/PYPPinyinEditor.cc
+++ b/src/PYPPinyinEditor.cc
@@ -20,3 +20,205 @@
*/
#include "PYPPinyinEditor.h"
+#include "PYConfig.h"
+#include "PYPinyinProperties.h"
+#include "PYSimpTradConverter.h"
+#include "PYHalfFullConverter.h"
+
+using namespace PY;
+
+/* init static members*/
+LibPinyinPinyinEditor::LibPinyinPinyinEditor (PinyinProperties & props,
+ Config & config)
+ : LibPinyinPhoneticEditor (props, config)
+{
+}
+
+
+/**
+ * process pinyin
+ */
+inline gboolean
+LibPinyinPinyinEditor::processPinyin (guint keyval, guint keycode,
+ guint modifiers)
+{
+ if (G_UNLIKELY (cmshm_filter (modifiers) != 0))
+ return m_text ? TRUE : FALSE;
+
+ return insert (keyval);
+}
+
+/**
+ * process numbers
+ */
+inline gboolean
+LibPinyinPinyinEditor::processNumber (guint keyval, guint keycode,
+ guint modifiers)
+{
+ guint i;
+
+ if (!m_text)
+ return FALSE;
+
+ switch (keyval) {
+ case IBUS_0:
+ case IBUS_KP_0:
+ i = 9;
+ break;
+ case IBUS_1 ... IBUS_9:
+ i = keyval - IBUS_1;
+ break;
+ case IBUS_KP_1 ... IBUS_KP_9:
+ i = keyval - IBUS_KP_1;
+ break;
+ default:
+ g_return_val_if_reached (FALSE);
+ }
+
+ if (modifiers == 0)
+ selectCandidateInPage (i);
+
+ return TRUE;
+}
+
+inline gboolean
+LibPinyinPinyinEditor::processPunct (guint keyval, guint keycode,
+ guint modifiers)
+{
+ if (m_text.empty ())
+ return FALSE;
+
+ if (cmshm_filter (modifiers) != 0)
+ return TRUE;
+
+ switch (keyval) {
+ case IBUS_apostrophe:
+ return insert (keyval);
+ case IBUS_comma:
+ if (m_config.commaPeriodPage ()) {
+ pageUp ();
+ return TRUE;
+ }
+ break;
+ case IBUS_minus:
+ if (m_config.minusEqualPage ()) {
+ pageUp ();
+ return TRUE;
+ }
+ break;
+ case IBUS_period:
+ if (m_config.commaPeriodPage ()) {
+ pageDown ();
+ return TRUE;
+ }
+ break;
+ case IBUS_equal:
+ if (m_config.minusEqualPage ()) {
+ pageDown ();
+ return TRUE;
+ }
+ break;
+ }
+
+ if (m_config.autoCommit ()) {
+ if (m_lookup_table.size ()) {
+ /* TODO: check here. */
+ selectCandidate (m_lookup_table.cursorPos ());
+ }
+ commit ();
+ return FALSE;
+ }
+
+ return TRUE;
+}
+
+inline gboolean
+LibPinyinPinyinEditor::processFunctionKey (guint keyval, guint keycode,
+ guint modifiers)
+{
+ if (m_text.empty ())
+ return FALSE;
+
+ /* ignore numlock */
+ modifiers = cmshm_filter (modifiers);
+
+ if (modifiers != 0 && modifiers != IBUS_CONTROL_MASK)
+ return TRUE;
+
+ /* process some cursor control keys */
+ if (modifiers == 0) { /* no modifiers. */
+ switch (keyval) {
+ case IBUS_Shift_L:
+ if (!m_config.shiftSelectCandidate ())
+ return FALSE;
+ selectCandidateInPage (1);
+ return TRUE;
+
+ case IBUS_Shift_R:
+ if (!m_config.shiftSelectCandidate ())
+ return FALSE;
+ selectCandidateInPage (2);
+ return TRUE;
+ }
+ }
+
+ return LibPinyinPhoneticEditor::processFunctionKey (keyval, keycode,
+ modifiers);
+}
+
+gboolean
+LibPinyinPinyinEditor::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);
+
+ switch (keyval) {
+ /* letters */
+ case IBUS_a ... IBUS_z:
+ return processPinyin (keyval, keycode, modifiers);
+ case IBUS_0 ... IBUS_9:
+ case IBUS_KP_0 ... IBUS_KP_9:
+ return processNumber (keyval, keycode, modifiers);
+ case IBUS_exclam ... IBUS_slash:
+ case IBUS_colon ... IBUS_at:
+ case IBUS_bracketleft ... IBUS_quoteleft:
+ case IBUS_braceleft ... IBUS_asciitilde:
+ return processPunct (keyval, keycode, modifiers);
+ case IBUS_space:
+ return processSpace (keyval, keycode, modifiers);
+ default:
+ return processFunctionKey (keyval, keycode, modifiers);
+ }
+}
+
+void
+LibPinyinPinyinEditor::commit ()
+{
+ g_assert (FALSE);
+}
+
+void
+LibPinyinPinyinEditor::updatePreeditText ()
+{
+ g_assert (FALSE);
+}
+
+void
+LibPinyinPinyinEditor::updateAuxiliaryText ()
+{
+ g_assert (FALSE);
+}
+
+void
+LibPinyinPinyinEditor::updateLookupTable ()
+{
+ m_lookup_table.setPageSize (m_config.pageSize ());
+ m_lookup_table.setOrientation (m_config.orientation ());
+ LibPinyinPhoneticEditor::updateLookupTable ();
+}