summaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorPeng Wu <alexepico@gmail.com>2011-09-19 16:10:48 +0800
committerPeng Wu <alexepico@gmail.com>2011-12-22 12:23:12 +0800
commit009663c6c618612a022bfb4cb9dd422e439f573f (patch)
tree096fb3362f98815b0ce43d644360ba8140e39b33 /src
parenta65345601ddcc396d0742c9c46164b8acf567d2b (diff)
downloadibus-libpinyin-009663c6c618612a022bfb4cb9dd422e439f573f.tar.gz
ibus-libpinyin-009663c6c618612a022bfb4cb9dd422e439f573f.tar.xz
ibus-libpinyin-009663c6c618612a022bfb4cb9dd422e439f573f.zip
write pinyin editor in progress
Diffstat (limited to 'src')
-rw-r--r--src/PYPPhoneticEditor.h2
-rw-r--r--src/PYPPinyinEditor.cc79
2 files changed, 77 insertions, 4 deletions
diff --git a/src/PYPPhoneticEditor.h b/src/PYPPhoneticEditor.h
index 32a5245..428f17b 100644
--- a/src/PYPPhoneticEditor.h
+++ b/src/PYPPhoneticEditor.h
@@ -25,7 +25,7 @@
#include "PYLookupTable.h"
#include "PYEditor.h"
#include "PYPinyinParser.h"
-#include "PYSpecialPhraseTable.h"
+
namespace PY {
diff --git a/src/PYPPinyinEditor.cc b/src/PYPPinyinEditor.cc
index a78544d..a435b82 100644
--- a/src/PYPPinyinEditor.cc
+++ b/src/PYPPinyinEditor.cc
@@ -200,19 +200,92 @@ LibPinyinPinyinEditor::processKeyEvent (guint keyval, guint keycode,
void
LibPinyinPinyinEditor::commit ()
{
- g_assert (FALSE);
+
+ if (G_UNLIKELY (m_buffer.empty ()))
+ return;
+
+ m_buffer.clear ();
+
+ /* sentence candidate */
+ char *tmp = NULL;
+ pinyin_get_sentence(m_instance, &tmp);
+ m_buffer << tmp;
+ g_free (tmp);
+ tmp = NULL;
+
+ /* text after pinyin */
+ const gchar *p = m_text.c_str() + m_pinyin_len;
+ if (G_UNLIKELY (m_props.modeFull ())) {
+ while (*p != '\0') {
+ m_buffer.appendUnichar (HalfFullConverter::toFull (*p++));
+ }
+ } else {
+ m_buffer << p;
+ }
+
+ pinyin_train(m_instance);
+ LibPinyinPhoneticEditor::commit ((const gchar *)m_buffer);
+ reset();
}
void
LibPinyinPinyinEditor::updatePreeditText ()
{
- g_assert (FALSE);
+ /* preedit text = guessed sentence + un-parsed pinyin text */
+ if (G_UNLIKELY (m_text.empty ())) {
+ hidePreeditText ();
+ return;
+ }
+
+ m_buffer.clear ();
+ char *tmp = NULL;
+ pinyin_get_sentence(m_instance, &tmp);
+ if (m_props.modeSimp ()) {
+ m_buffer<<tmp;
+ } else {
+ SimpTradConverter::simpToTrad (tmp, m_buffer);
+ }
+ g_free (tmp);
+ tmp = NULL;
+
+ /* append rest text */
+ const gchar *p = m_text.c_str () + m_pinyin_len;
+ m_buffer << p;
+
+ StaticText preedit_text (m_buffer);
+ /* underline */
+ preedit_text.appendAttribute (IBUS_ATTR_TYPE_UNDERLINE, IBUS_ATTR_UNDERLINE_SINGLE, 0, -1);
+
+ guint pinyin_cursor = getPinyinCursor ();
+ Editor::updatePreeditText (preedit_text, pinyin_cursor, TRUE);
}
void
LibPinyinPinyinEditor::updateAuxiliaryText ()
{
- g_assert (FALSE);
+ if (G_UNLIKELY (m_text.empty ())) {
+ hideAuxiliaryText ();
+ return;
+ }
+
+ m_buffer.clear ();
+
+ /* Note: cursor handling is defered to full/double pinyin editors. */
+ guint pinyin_cursor = getPinyinCursor ();
+ for (guint i = 0; i < m_pinyins.size (); ++i) {
+ if (G_LIKELY (i))
+ m_buffer << ' ';
+ const Pinyin *pinyin = m_pinyins[i];
+ m_buffer << pinyin->sheng
+ << pinyin->yun;
+ }
+
+ /* 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);
}
void