summaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorPeng Wu <alexepico@gmail.com>2011-09-22 14:24:09 +0800
committerPeng Wu <alexepico@gmail.com>2011-12-22 12:23:12 +0800
commitcb25a0b9ee36d12d09ef9a0644888bfd2066252a (patch)
tree383ff0ebb6f7eaf44347d03ad6b53ac0776f23a8 /src
parentdde9caeb198ab9756555ac8e040090941e53abba (diff)
downloadibus-libpinyin-cb25a0b9ee36d12d09ef9a0644888bfd2066252a.tar.gz
ibus-libpinyin-cb25a0b9ee36d12d09ef9a0644888bfd2066252a.tar.xz
ibus-libpinyin-cb25a0b9ee36d12d09ef9a0644888bfd2066252a.zip
write double pinyin editor
Diffstat (limited to 'src')
-rw-r--r--src/PYPDoublePinyinEditor.cc93
-rw-r--r--src/PYPDoublePinyinEditor.h1
-rw-r--r--src/PYPFullPinyinEditor.cc2
-rw-r--r--src/PYPPinyinEditor.cc2
4 files changed, 96 insertions, 2 deletions
diff --git a/src/PYPDoublePinyinEditor.cc b/src/PYPDoublePinyinEditor.cc
index 501ec30..0e1e3d3 100644
--- a/src/PYPDoublePinyinEditor.cc
+++ b/src/PYPDoublePinyinEditor.cc
@@ -20,9 +20,64 @@
*/
#include "PYPDoublePinyinEditor.h"
+#include "PYConfig.h"
+
+#define DEFINE_DOUBLE_PINYIN_TABLES
+#include "PYDoublePinyinTable.h"
using namespace PY;
+/*
+ * c in 'a' ... 'z' => id = c - 'a'
+ * c == ';' => id = 26
+ * else => id = -1
+ */
+#define ID(c) \
+ ((c >= IBUS_a && c <= IBUS_z) ? c - IBUS_a : (c == IBUS_semicolon ? 26 : -1))
+
+#define ID_TO_SHENG(id) \
+ (double_pinyin_map[m_config.doublePinyinSchema ()].sheng[id])
+#define ID_TO_YUNS(id) \
+ (double_pinyin_map[m_config.doublePinyinSchema ()].yun[id])
+
+#define IS_ALPHA(c) \
+ ((c >= 'a' && c <= 'z') || (c >= 'A' && c <= 'Z'))
+
+
+LibPinyinDoublePinyinEditor::LibPinyinDoublePinyinEditor
+( PinyinProperties & props, Config & config)
+ : LibPinyinPinyinEditor (props, config)
+{
+}
+
+gboolean
+LibPinyinDoublePinyinEditor::insert (gint ch)
+{
+ /* is full */
+ if (G_UNLIKELY (m_text.length () >= MAX_PINYIN_LEN))
+ return TRUE;
+
+ gint id = ID (ch);
+ if (id == -1) {
+ /* it is not available ch */
+ return FALSE;
+ }
+
+ if (G_UNLIKELY (m_text.empty () && ID_TO_SHENG (id) == PINYIN_ID_VOID)) {
+ return FALSE;
+ }
+
+ m_text.insert (m_cursor++, ch);
+ updatePinyin ();
+ update ();
+
+ return TRUE;
+}
+
+void LibPinyinDoublePinyinEditor::reset (void)
+{
+ LibPinyinPinyinEditor::reset ();
+}
gboolean
LibPinyinDoublePinyinEditor::processKeyEvent (guint keyval, guint keycode,
@@ -54,3 +109,41 @@ LibPinyinDoublePinyinEditor::updatePinyin (void)
pinyin_parse_more_double_pinyins (m_instance, m_text.c_str ());
pinyin_guess_sentence (m_instance);
}
+
+
+void
+LibPinyinDoublePinyinEditor::updateAuxiliaryText (void)
+{
+ if (G_UNLIKELY (m_text.empty ())) {
+ hideAuxiliaryText ();
+ return;
+ }
+
+ m_buffer.clear ();
+
+ // guint pinyin_cursor = getPinyinCursor ();
+ PinyinKeyVector & pinyin_keys = m_instance->m_pinyin_keys;
+ PinyinKeyPosVector & pinyin_poses = m_instance->m_pinyin_poses;
+ for (guint i = 0; i < pinyin_keys->len; ++i) {
+ PinyinKey *key = &g_array_index (pinyin_keys, PinyinKey, i);
+ PinyinKeyPos *pos = &g_array_index (pinyin_poses, PinyinKeyPos, i);
+ guint cursor = pos->get_pos ();
+
+ if (G_UNLIKELY (cursor == m_cursor)) { /* at word boundary. */
+ m_buffer << '|' << key->get_key_string ();
+ } else { /* in word */
+ /* raw text */
+ String raw = m_text.substr (cursor, pos->get_length ());
+ guint offset = m_cursor - cursor;
+ m_buffer << ' ' << raw.substr (0, offset)
+ << '|' << raw.substr (offset);
+ }
+ }
+
+ /* append rest text */
+ const gchar * p = m_text.c_str() + m_pinyin_len;
+ m_buffer << p;
+
+ StaticText aux_text (m_buffer);
+ Editor::updateAuxiliaryText (aux_text, TRUE);
+}
diff --git a/src/PYPDoublePinyinEditor.h b/src/PYPDoublePinyinEditor.h
index d756fbd..b06e144 100644
--- a/src/PYPDoublePinyinEditor.h
+++ b/src/PYPDoublePinyinEditor.h
@@ -38,6 +38,7 @@ public:
protected:
/* TODO: to be implemented. */
+ virtual void updateAuxiliaryText (void);
virtual void updatePinyin (void);
};
diff --git a/src/PYPFullPinyinEditor.cc b/src/PYPFullPinyinEditor.cc
index 05de60d..80f8a46 100644
--- a/src/PYPFullPinyinEditor.cc
+++ b/src/PYPFullPinyinEditor.cc
@@ -107,7 +107,7 @@ LibPinyinFullPinyinEditor::updateAuxiliaryText ()
m_buffer.clear ();
- guint pinyin_cursor = getPinyinCursor ();
+ // guint pinyin_cursor = getPinyinCursor ();
PinyinKeyVector & pinyin_keys = m_instance->m_pinyin_keys;
PinyinKeyPosVector & pinyin_poses = m_instance->m_pinyin_poses;
for (guint i = 0; i < pinyin_keys->len; ++i) {
diff --git a/src/PYPPinyinEditor.cc b/src/PYPPinyinEditor.cc
index 08fc04e..8108002 100644
--- a/src/PYPPinyinEditor.cc
+++ b/src/PYPPinyinEditor.cc
@@ -271,7 +271,7 @@ LibPinyinPinyinEditor::updateAuxiliaryText ()
m_buffer.clear ();
/* Note: cursor handling is defered to full/double pinyin editors. */
- guint pinyin_cursor = getPinyinCursor ();
+ // guint pinyin_cursor = getPinyinCursor ();
PinyinKeyVector & pinyin_keys = m_instance->m_pinyin_keys;
for (guint i = 0; i < pinyin_keys->len; ++i) {
if (G_LIKELY (i))