1 /* vim:set et ts=4 sts=4:
3 * ibus-pinyin - The Chinese PinYin engine for IBus
5 * Copyright (c) 2011 Peng Wu <alexepico@gmail.com>
7 * This program is free software; you can redistribute it and/or modify
8 * it under the terms of the GNU General Public License as published by
9 * the Free Software Foundation; either version 2, or (at your option)
12 * This program is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 * GNU General Public License for more details.
17 * You should have received a copy of the GNU General Public License
18 * along with this program; if not, write to the Free Software
19 * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
22 #include "PYPFullPinyinEditor.h"
24 #include "PYLibPinyin.h"
28 LibPinyinFullPinyinEditor::LibPinyinFullPinyinEditor
29 (PinyinProperties & props, Config & config)
30 : LibPinyinPinyinEditor (props, config)
32 m_instance = LibPinyinBackEnd::instance ().allocPinyinInstance ();
35 LibPinyinFullPinyinEditor::~LibPinyinFullPinyinEditor (void)
37 LibPinyinBackEnd::instance ().freePinyinInstance (m_instance);
42 LibPinyinFullPinyinEditor::reset (void)
44 LibPinyinPinyinEditor::reset ();
48 LibPinyinFullPinyinEditor::insert (gint ch)
51 if (G_UNLIKELY (m_text.length () >= MAX_PINYIN_LEN))
54 m_text.insert (m_cursor++, ch);
63 LibPinyinFullPinyinEditor::processKeyEvent (guint keyval,
67 return LibPinyinPinyinEditor::processKeyEvent (keyval, keycode, modifiers);
71 LibPinyinFullPinyinEditor::updatePinyin (void)
73 if (G_UNLIKELY (m_text.empty ())) {
75 /* TODO: check whether to replace "" with NULL. */
76 pinyin_parse_more_full_pinyins (m_instance, "");
81 pinyin_parse_more_full_pinyins (m_instance, m_text.c_str ());
82 pinyin_guess_sentence (m_instance);
86 LibPinyinFullPinyinEditor::updateAuxiliaryText ()
88 if (G_UNLIKELY (m_text.empty ())) {
95 // guint pinyin_cursor = getPinyinCursor ();
96 PinyinKeyVector & pinyin_keys = m_instance->m_pinyin_keys;
97 PinyinKeyPosVector & pinyin_poses = m_instance->m_pinyin_key_rests;
98 for (guint i = 0; i < pinyin_keys->len; ++i) {
99 PinyinKey *key = &g_array_index (pinyin_keys, PinyinKey, i);
100 PinyinKeyPos *pos = &g_array_index (pinyin_poses, PinyinKeyPos, i);
101 guint cursor = pos->m_raw_begin;
103 if (G_UNLIKELY (cursor == m_cursor)) { /* at word boundary. */
104 m_buffer << '|' << key->get_pinyin_string ();
105 } else if (G_LIKELY ( cursor < m_cursor &&
106 m_cursor < pos->m_raw_end )) { /* in word */
108 String raw = m_text.substr (cursor,
110 guint offset = m_cursor - cursor;
111 m_buffer << ' ' << raw.substr (0, offset)
112 << '|' << raw.substr (offset);
113 } else { /* other words */
114 m_buffer << ' ' << key->get_pinyin_string ();
118 if (m_cursor == m_pinyin_len)
121 /* append rest text */
122 const gchar * p = m_text.c_str() + m_pinyin_len;
125 StaticText aux_text (m_buffer);
126 Editor::updateAuxiliaryText (aux_text, TRUE);