From 0be5dc6e762d622c3d0662a6f4d1d54f26b187ed Mon Sep 17 00:00:00 2001 From: Peng Wu Date: Wed, 30 May 2012 13:31:29 +0800 Subject: [PATCH] remove old files --- src/PYBopomofoEditor.cc | 633 -------------------------------------------- src/PYBopomofoEditor.h | 78 ------ src/PYBopomofoEngine.cc | 260 ------------------ src/PYBopomofoEngine.h | 82 ------ src/PYDoublePinyinEditor.cc | 489 ---------------------------------- src/PYDoublePinyinEditor.h | 63 ----- src/PYFullPinyinEditor.cc | 241 ----------------- src/PYFullPinyinEditor.h | 64 ----- 8 files changed, 1910 deletions(-) delete mode 100644 src/PYBopomofoEditor.cc delete mode 100644 src/PYBopomofoEditor.h delete mode 100644 src/PYBopomofoEngine.cc delete mode 100644 src/PYBopomofoEngine.h delete mode 100644 src/PYDoublePinyinEditor.cc delete mode 100644 src/PYDoublePinyinEditor.h delete mode 100644 src/PYFullPinyinEditor.cc delete mode 100644 src/PYFullPinyinEditor.h diff --git a/src/PYBopomofoEditor.cc b/src/PYBopomofoEditor.cc deleted file mode 100644 index e0a76c1..0000000 --- a/src/PYBopomofoEditor.cc +++ /dev/null @@ -1,633 +0,0 @@ -/* vim:set et ts=4 sts=4: - * - * ibus-pinyin - The Chinese PinYin engine for IBus - * - * Copyright (c) 2008-2010 Peng Huang - * Copyright (c) 2010 BYVoid - * - * This program is free software; you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation; either version 2, or (at your option) - * any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program; if not, write to the Free Software - * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. - */ -#include "PYBopomofoEditor.h" -#include "PYConfig.h" -#include "PYPinyinProperties.h" -#include "PYSimpTradConverter.h" - -namespace PY { -#include "PYBopomofoKeyboard.h" - -const static gchar * bopomofo_select_keys[] = { - "1234567890", - "asdfghjkl;", - "1qaz2wsxed", - "asdfzxcvgb", - "1234qweras", - "aoeu;qjkix", - "aoeuhtnsid", - "aoeuidhtns", - "qweasdzxcr" -}; - -BopomofoEditor::BopomofoEditor (PinyinProperties & props, Config & config) - : PhoneticEditor (props, config), - m_select_mode (FALSE) -{ -} - -BopomofoEditor::~BopomofoEditor (void) -{ -} - -void -BopomofoEditor::reset (void) -{ - m_select_mode = FALSE; - PhoneticEditor::reset (); -} - -gboolean -BopomofoEditor::insert (gint ch) -{ - /* is full */ - if (G_UNLIKELY (m_text.length () >= MAX_PINYIN_LEN)) - return TRUE; - - m_text.insert (m_cursor++, ch); - - if (G_UNLIKELY (!(m_config.option () & PINYIN_INCOMPLETE_PINYIN))) { - updateSpecialPhrases (); - updatePinyin (); - } - else if (G_LIKELY (m_cursor <= m_pinyin_len + 2)) { - updateSpecialPhrases (); - updatePinyin (); - } - else { - if (updateSpecialPhrases ()) { - update (); - } - else { - updatePreeditText (); - updateAuxiliaryText (); - } - } - return TRUE; -} - -gboolean -BopomofoEditor::removeCharBefore (void) -{ - if (G_UNLIKELY (m_cursor == 0)) - return FALSE; - - m_cursor --; - m_text.erase (m_cursor, 1); - - updateSpecialPhrases (); - updatePinyin (); - - return TRUE; -} - -gboolean -BopomofoEditor::removeCharAfter (void) -{ - if (G_UNLIKELY (m_cursor == m_text.length ())) - return FALSE; - - m_text.erase (m_cursor, 1); - updatePreeditText (); - updateAuxiliaryText (); - - return TRUE; -} - -gboolean -BopomofoEditor::removeWordBefore (void) -{ - if (G_UNLIKELY (m_cursor == 0)) - return FALSE; - - guint cursor; - - if (G_UNLIKELY (m_cursor > m_pinyin_len)) { - cursor = m_pinyin_len; - } - else { - const Pinyin & p = *m_pinyin.back (); - cursor = m_cursor - p.len; - m_pinyin_len -= p.len; - m_pinyin.pop_back (); - } - - m_text.erase (cursor, m_cursor - cursor); - m_cursor = cursor; - updateSpecialPhrases (); - updatePhraseEditor (); - update (); - return TRUE; -} - -gboolean -BopomofoEditor::removeWordAfter (void) -{ - if (G_UNLIKELY (m_cursor == m_text.length ())) - return FALSE; - - m_text.erase (m_cursor, -1); - updatePreeditText (); - updateAuxiliaryText (); - return TRUE; -} - -gboolean -BopomofoEditor::moveCursorLeft (void) -{ - if (G_UNLIKELY (m_cursor == 0)) - return FALSE; - - m_cursor --; - updateSpecialPhrases (); - updatePinyin (); - - return TRUE; -} - -gboolean -BopomofoEditor::moveCursorRight (void) -{ - if (G_UNLIKELY (m_cursor == m_text.length ())) - return FALSE; - - m_cursor ++; - - updateSpecialPhrases (); - updatePinyin (); - - return TRUE; -} - -gboolean -BopomofoEditor::moveCursorLeftByWord (void) -{ - if (G_UNLIKELY (m_cursor == 0)) - return FALSE; - - if (G_UNLIKELY (m_cursor > m_pinyin_len)) { - m_cursor = m_pinyin_len; - return TRUE; - } - - const Pinyin & p = *m_pinyin.back (); - m_cursor -= p.len; - m_pinyin_len -= p.len; - m_pinyin.pop_back (); - - updateSpecialPhrases (); - updatePhraseEditor (); - update (); - - return TRUE; -} - -gboolean -BopomofoEditor::moveCursorRightByWord (void) -{ - return moveCursorToEnd (); -} - -gboolean -BopomofoEditor::moveCursorToBegin (void) -{ - if (G_UNLIKELY (m_cursor == 0)) - return FALSE; - - m_cursor = 0; - m_pinyin.clear (); - m_pinyin_len = 0; - - updateSpecialPhrases (); - updatePhraseEditor (); - update (); - - return TRUE; -} - -gboolean -BopomofoEditor::moveCursorToEnd (void) -{ - if (G_UNLIKELY (m_cursor == m_text.length ())) - return FALSE; - - m_cursor = m_text.length (); - updateSpecialPhrases (); - updatePinyin (); - - return TRUE; -} - -gboolean -BopomofoEditor::processGuideKey (guint keyval, guint keycode, guint modifiers) -{ - if (!m_config.guideKey ()) - return FALSE; - - if (G_UNLIKELY (cmshm_filter (modifiers) != 0)) - return FALSE; - - if (G_LIKELY (m_select_mode)) - return FALSE; - - if (G_UNLIKELY (keyval == IBUS_space)) { - m_select_mode = TRUE; - updateLookupTable (); - return TRUE; - } - - return FALSE; -} - -gboolean -BopomofoEditor::processAuxiliarySelectKey (guint keyval, guint keycode, guint modifiers) -{ - if (G_UNLIKELY (cmshm_filter (modifiers) != 0)) - return FALSE; - - guint i; - - switch (keyval) { - case IBUS_KP_0: - i = 9; - if (!m_config.auxiliarySelectKeyKP ()) - return FALSE; - break; - case IBUS_KP_1 ... IBUS_KP_9: - i = keyval - IBUS_KP_1; - if (!m_config.auxiliarySelectKeyKP ()) - return FALSE; - break; - case IBUS_F1 ... IBUS_F10: - i = keyval - IBUS_F1; - if (!m_config.auxiliarySelectKeyF ()) - return FALSE; - break; - default: - return FALSE; - } - - m_select_mode = TRUE; - selectCandidateInPage (i); - - return TRUE; -} - -gboolean -BopomofoEditor::processSelectKey (guint keyval, guint keycode, guint modifiers) -{ - if (G_UNLIKELY (!m_text)) - return FALSE; - - if (G_LIKELY (!m_select_mode && ((modifiers & IBUS_MOD1_MASK) == 0))) - return FALSE; - - const gchar * pos = strchr (bopomofo_select_keys[m_config.selectKeys ()], keyval); - if (pos == NULL) - return FALSE; - - m_select_mode = TRUE; - - guint i = pos - bopomofo_select_keys[m_config.selectKeys ()]; - selectCandidateInPage (i); - - return TRUE; -} - -gboolean -BopomofoEditor::processBopomofo (guint keyval, guint keycode, guint modifiers) -{ - if (G_UNLIKELY (cmshm_filter (modifiers) != 0)) - return m_text ? TRUE : FALSE; - - if (keyvalToBopomofo (keyval) == BOPOMOFO_ZERO) - return FALSE; - - m_select_mode = FALSE; - - return insert (keyval); -} - -gboolean -BopomofoEditor::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 (G_UNLIKELY (processGuideKey (keyval, keycode, modifiers))) - return TRUE; - if (G_UNLIKELY (processSelectKey (keyval, keycode, modifiers) == TRUE)) - return TRUE; - if (G_UNLIKELY (processAuxiliarySelectKey (keyval, keycode, modifiers))) - return TRUE; - if (G_UNLIKELY (processBopomofo (keyval, keycode ,modifiers))) - return TRUE; - - switch (keyval) { - case IBUS_space: - m_select_mode = TRUE; - return processSpace (keyval, keycode, modifiers); - - case IBUS_Up: - case IBUS_KP_Up: - case IBUS_Down: - case IBUS_KP_Down: - case IBUS_Page_Up: - case IBUS_KP_Page_Up: - case IBUS_Page_Down: - case IBUS_KP_Page_Down: - case IBUS_Tab: - m_select_mode = TRUE; - return PhoneticEditor::processFunctionKey (keyval, keycode, modifiers); - - case IBUS_BackSpace: - case IBUS_Delete: - case IBUS_KP_Delete: - case IBUS_Left: - case IBUS_KP_Left: - case IBUS_Right: - case IBUS_KP_Right: - case IBUS_Home: - case IBUS_KP_Home: - case IBUS_End: - case IBUS_KP_End: - m_select_mode = FALSE; - return PhoneticEditor::processFunctionKey (keyval, keycode, modifiers); - - default: - return PhoneticEditor::processFunctionKey (keyval, keycode, modifiers); - } - -} - -void -BopomofoEditor::updatePinyin (void) -{ - if (G_UNLIKELY (m_text.empty ())) { - m_pinyin.clear (); - m_pinyin_len = 0; - } - else { - bopomofo.clear(); - for(String::iterator i = m_text.begin (); i != m_text.end (); ++i) { - bopomofo += bopomofo_char[keyvalToBopomofo (*i)]; - } - - m_pinyin_len = PinyinParser::parseBopomofo (bopomofo, // bopomofo - m_cursor, // text length - m_config.option (), // option - m_pinyin, // result - MAX_PHRASE_LEN); // max result length - } - - updatePhraseEditor (); - update (); -} - -void -BopomofoEditor::updateAuxiliaryText (void) -{ - if (G_UNLIKELY (m_text.empty () || - m_lookup_table.size () == 0)) { - hideAuxiliaryText (); - return; - } - - m_buffer.clear (); - - guint si = 0; - guint m_text_len = m_text.length(); - for (guint i = m_phrase_editor.cursor (); i < m_pinyin.size (); ++i) { - if (G_LIKELY (i != m_phrase_editor.cursor ())) - m_buffer << ','; - m_buffer << (gunichar *)m_pinyin[i]->bopomofo; - for (guint sj = 0; m_pinyin[i]->bopomofo[sj] == bopomofo_char[keyvalToBopomofo(m_text.c_str()[si])] ; si++,sj++); - if (si < m_text_len) { - gint ch = keyvalToBopomofo(m_text.c_str()[si]); - if (ch >= BOPOMOFO_TONE_2 && ch <= BOPOMOFO_TONE_5) { - m_buffer.appendUnichar(bopomofo_char[ch]); - ++si; - } - } - } - - for (String::iterator i = m_text.begin () + m_pinyin_len; i != m_text.end (); i++) { - if (m_cursor == (guint)(i - m_text.begin ())) - m_buffer << '|'; - m_buffer.appendUnichar (bopomofo_char[keyvalToBopomofo (*i)]); - } - if (m_cursor == m_text.length ()) - m_buffer << '|'; - - StaticText aux_text (m_buffer); - Editor::updateAuxiliaryText (aux_text, TRUE); -} - -void -BopomofoEditor::commit (void) -{ - if (G_UNLIKELY (m_buffer.empty ())) - return; - - m_buffer.clear (); - - if (!m_select_mode && m_config.enterKey ()) { - m_phrase_editor.selectCandidate(0); - } - - - if (m_select_mode || m_config.enterKey ()) { - m_buffer << m_phrase_editor.selectedString (); - - const gchar *p; - - if (m_selected_special_phrase.empty ()) { - p = textAfterPinyin (m_buffer.utf8Length ()); - } - else { - m_buffer << m_selected_special_phrase; - p = textAfterCursor (); - } - - while (*p != '\0') { - m_buffer.appendUnichar ((gunichar)bopomofo_char[keyvalToBopomofo (*p++)]); - } - } - else { - m_buffer << m_text; - } - - m_phrase_editor.commit (); - reset (); - PhoneticEditor::commit ((const gchar *)m_buffer); -} - -void -BopomofoEditor::updatePreeditText (void) -{ - /* preedit text = selected phrases + highlight candidate + rest text */ - if (G_UNLIKELY (m_phrase_editor.empty () && m_text.empty ())) { - hidePreeditText (); - return; - } - - guint edit_begin = 0; - guint edit_end = 0; - - m_buffer.clear (); - - /* add selected phrases */ - m_buffer << m_phrase_editor.selectedString (); - - if (G_UNLIKELY (! m_selected_special_phrase.empty ())) { - /* add selected special phrase */ - m_buffer << m_selected_special_phrase; - edit_begin = m_buffer.utf8Length (); - - /* append text after cursor */ - m_buffer << textAfterCursor (); - } - else { - edit_begin = m_buffer.utf8Length (); - if (m_lookup_table.size () > 0) { - guint cursor = m_lookup_table.cursorPos (); - - if (cursor < m_special_phrases.size ()) { - m_buffer << m_special_phrases[cursor].c_str (); - edit_end = m_buffer.utf8Length (); - /* append text after cursor */ - m_buffer << textAfterCursor (); - } - else { - const Phrase & candidate = m_phrase_editor.candidate (cursor - m_special_phrases.size ()); - if (m_text.size () == m_cursor) { - /* cursor at end */ - if (m_props.modeSimp ()) - m_buffer << candidate; - else - SimpTradConverter::simpToTrad (candidate, m_buffer); - edit_end = m_buffer.utf8Length (); - - /* append rest text */ - for (const gchar *p=m_text.c_str() + m_pinyin_len; *p ;++p) { - m_buffer.appendUnichar(bopomofo_char[keyvalToBopomofo(*p)]); - } - } - else { - for (const gchar *p = m_text.c_str (); *p; ++p) { - if ((guint) (p - m_text.c_str ()) == m_cursor) - m_buffer << ' '; - m_buffer.appendUnichar (bopomofo_char[keyvalToBopomofo (*p)]); - } - edit_end = m_buffer.utf8Length (); - } - } - } - else { - for (const gchar *p=m_text.c_str () + m_pinyin_len; *p ; ++p) { - m_buffer.appendUnichar (bopomofo_char[keyvalToBopomofo (*p)]); - } - } - } - - StaticText preedit_text (m_buffer); - /* underline */ - preedit_text.appendAttribute (IBUS_ATTR_TYPE_UNDERLINE, IBUS_ATTR_UNDERLINE_SINGLE, 0, -1); - - /* candidate */ - if (edit_begin < edit_end) { - preedit_text.appendAttribute (IBUS_ATTR_TYPE_FOREGROUND, 0x00000000, - edit_begin, edit_end); - preedit_text.appendAttribute (IBUS_ATTR_TYPE_BACKGROUND, 0x00c8c8f0, - edit_begin, edit_end); - } - Editor::updatePreeditText (preedit_text, edit_begin, TRUE); -} - -void -BopomofoEditor::updateLookupTableLabel () -{ - std::string str; - guint color = m_select_mode ? 0x000000 : 0xBBBBBB; - for (const gchar *p = bopomofo_select_keys[m_config.selectKeys ()]; *p; p++) - { - guint i = p - bopomofo_select_keys[m_config.selectKeys ()]; - if (i >= m_config.pageSize ()) - break; - str = *p; - str += "."; - Text text_label (str); - text_label.appendAttribute (IBUS_ATTR_TYPE_FOREGROUND, color, 0, -1); - m_lookup_table.setLabel (i, text_label); - } - if (m_config.guideKey ()) - m_lookup_table.setCursorVisable (m_select_mode); - else - m_lookup_table.setCursorVisable (TRUE); -} - -void -BopomofoEditor::updateLookupTableFast () -{ - updateLookupTableLabel (); - PhoneticEditor::updateLookupTableFast (); -} - -void -BopomofoEditor::updateLookupTable () -{ - m_lookup_table.setPageSize (m_config.pageSize ()); - m_lookup_table.setOrientation (m_config.orientation ()); - updateLookupTableLabel (); - PhoneticEditor::updateLookupTable (); -} - -static gint -keyboard_cmp (gconstpointer p1, gconstpointer p2) -{ - const gint s1 = GPOINTER_TO_INT (p1); - const guint8 *s2 = (const guint8 *) p2; - return s1 - s2[0]; -} - -gint -BopomofoEditor::keyvalToBopomofo(gint ch) -{ - const gint keyboard = m_config.bopomofoKeyboardMapping (); - const guint8 *brs; - brs = (const guint8 *) std::bsearch (GINT_TO_POINTER (ch), - bopomofo_keyboard[keyboard], - G_N_ELEMENTS (bopomofo_keyboard[keyboard]), - sizeof(bopomofo_keyboard[keyboard][0]), - keyboard_cmp); - if (G_UNLIKELY (brs == NULL)) - return BOPOMOFO_ZERO; - return brs[1]; -} - -}; diff --git a/src/PYBopomofoEditor.h b/src/PYBopomofoEditor.h deleted file mode 100644 index 8ad9784..0000000 --- a/src/PYBopomofoEditor.h +++ /dev/null @@ -1,78 +0,0 @@ -/* vim:set et ts=4 sts=4: - * - * ibus-pinyin - The Chinese PinYin engine for IBus - * - * Copyright (c) 2008-2010 Peng Huang - * Copyright (c) 2010 BYVoid - * - * This program is free software; you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation; either version 2, or (at your option) - * any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program; if not, write to the Free Software - * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. - */ -#ifndef __PY_BOPOMOFO_EDITOR_H_ -#define __PY_BOPOMOFO_EDITOR_H_ - -#include "PYPhoneticEditor.h" - -namespace PY { - -class Config; - -#define MAX_PINYIN_LEN 64 - -class BopomofoEditor : public PhoneticEditor { - -public: - BopomofoEditor (PinyinProperties & props, Config & config); - ~BopomofoEditor (void); - -protected: - std::wstring bopomofo; - gboolean m_select_mode; - - gboolean processGuideKey (guint keyval, guint keycode, guint modifiers); - gboolean processAuxiliarySelectKey (guint keyval, guint keycode, guint modifiers); - gboolean processSelectKey (guint keyval, guint keycode, guint modifiers); - gboolean processBopomofo (guint keyval, guint keycode, guint modifiers); - gboolean processKeyEvent (guint keyval, guint keycode, guint modifiers); - - void updateAuxiliaryText (); - void updateLookupTable (); - void updateLookupTableFast (); - void updateLookupTableLabel (); - void updatePinyin (); - void updatePreeditText (); - - void commit (); - void reset (); - - gboolean insert (gint ch); - gint keyvalToBopomofo(gint ch); - - gboolean removeCharBefore (void); - gboolean removeCharAfter (void); - gboolean removeWordBefore (void); - gboolean removeWordAfter (void); - - gboolean moveCursorLeft (void); - gboolean moveCursorRight (void); - gboolean moveCursorLeftByWord (void); - gboolean moveCursorRightByWord (void); - gboolean moveCursorToBegin (void); - gboolean moveCursorToEnd (void); - -}; - -}; - -#endif diff --git a/src/PYBopomofoEngine.cc b/src/PYBopomofoEngine.cc deleted file mode 100644 index 5945eb6..0000000 --- a/src/PYBopomofoEngine.cc +++ /dev/null @@ -1,260 +0,0 @@ -/* vim:set et ts=4 sts=4: - * - * ibus-pinyin - The Chinese PinYin engine for IBus - * - * Copyright (c) 2008-2010 Peng Huang - * Copyright (c) 2010 BYVoid - * - * This program is free software; you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation; either version 2, or (at your option) - * any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program; if not, write to the Free Software - * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. - */ -#include "PYBopomofoEngine.h" -#include -#include "PYRawEditor.h" -#include "PYPunctEditor.h" -#ifdef IBUS_BUILD_LUA_EXTENSION -#include "PYExtEditor.h" -#endif -#include "PYBopomofoEditor.h" -#include "PYFallbackEditor.h" -#include "PYConfig.h" - -namespace PY { - -/* constructor */ -BopomofoEngine::BopomofoEngine (IBusEngine *engine) - : Engine (engine), - m_props (BopomofoConfig::instance ()), - m_prev_pressed_key (IBUS_VoidSymbol), - m_input_mode (MODE_INIT), - m_fallback_editor (new FallbackEditor (m_props, BopomofoConfig::instance ())) -{ - gint i; - - /* create editors */ - m_editors[MODE_INIT].reset (new BopomofoEditor (m_props, BopomofoConfig::instance ())); - m_editors[MODE_PUNCT].reset (new PunctEditor (m_props, BopomofoConfig::instance ())); - - m_editors[MODE_RAW].reset (new RawEditor (m_props, BopomofoConfig::instance ())); -#ifdef IBUS_BUILD_LUA_EXTENSION - m_editors[MODE_EXTENSION].reset (new ExtEditor (m_props, BopomofoConfig::instance ())); -#else - m_editors[MODE_EXTENSION].reset (new Editor (m_props, BopomofoConfig::instance ())); -#endif - - m_props.signalUpdateProperty ().connect (std::bind (&BopomofoEngine::updateProperty, this, _1)); - - for (i = MODE_INIT; i < MODE_LAST; i++) { - connectEditorSignals (m_editors[i]); - } - - connectEditorSignals (m_fallback_editor); -} - -/* destructor */ -BopomofoEngine::~BopomofoEngine (void) -{ -} - -gboolean -BopomofoEngine::processKeyEvent (guint keyval, guint keycode, guint modifiers) -{ - gboolean retval = FALSE; - - /* check Shift + Release hotkey, - * and then ignore other Release key event */ - if (modifiers & IBUS_RELEASE_MASK) { - /* press and release keyval are same, - * and no other key event between the press and release ket event*/ - if (m_prev_pressed_key == keyval) { - if (keyval == IBUS_Shift_L || keyval == IBUS_Shift_R) { - if (!m_editors[MODE_INIT]->text ().empty ()) - m_editors[MODE_INIT]->reset (); - m_props.toggleModeChinese (); - return TRUE; - } - } - - if (m_input_mode == MODE_INIT && - m_editors[MODE_INIT]->text ().empty ()) { - /* If it is init mode, and no any previouse input text, - * we will let client applications to handle release key event */ - return FALSE; - } - else { - return TRUE; - } - } - - /* Toggle simp/trad Chinese Mode when hotkey Ctrl + Shift + F pressed */ - if (keyval == IBUS_F && scmshm_test (modifiers, (IBUS_SHIFT_MASK | IBUS_CONTROL_MASK))) { - m_props.toggleModeSimp(); - m_prev_pressed_key = IBUS_F; - return TRUE; - } - - if (m_props.modeChinese ()) { - if (G_UNLIKELY (m_input_mode == MODE_INIT && - m_editors[MODE_INIT]->text ().empty () && - (cmshm_filter (modifiers)) == 0) && - keyval == IBUS_grave) { - /* if BopomofoEditor is empty and get a grave key, - * switch current editor to PunctEditor */ - m_input_mode = MODE_PUNCT; - } - - retval = m_editors[m_input_mode]->processKeyEvent (keyval, keycode, modifiers); - if (G_UNLIKELY (retval && - m_input_mode != MODE_INIT && - m_editors[m_input_mode]->text ().empty ())) - m_input_mode = MODE_INIT; - } - - if (G_UNLIKELY (!retval)) - retval = m_fallback_editor->processKeyEvent (keyval, keycode, modifiers); - - /* store ignored key event by editors */ - m_prev_pressed_key = retval ? IBUS_VoidSymbol : keyval; - - return retval; -} - -void -BopomofoEngine::focusIn (void) -{ - registerProperties (m_props.properties ()); -} - -void -BopomofoEngine::focusOut (void) -{ - reset (); -} - -void -BopomofoEngine::reset (void) -{ - m_prev_pressed_key = IBUS_VoidSymbol; - m_input_mode = MODE_INIT; - for (gint i = 0; i < MODE_LAST; i++) { - m_editors[i]->reset (); - } - m_fallback_editor->reset (); -} - -void -BopomofoEngine::enable (void) -{ - m_props.reset (); -} - -void -BopomofoEngine::disable (void) -{ -} - -void -BopomofoEngine::pageUp (void) -{ - m_editors[m_input_mode]->pageUp (); -} - -void -BopomofoEngine::pageDown (void) -{ - m_editors[m_input_mode]->pageDown (); -} - -void -BopomofoEngine::cursorUp (void) -{ - m_editors[m_input_mode]->cursorUp (); -} - -void -BopomofoEngine::cursorDown (void) -{ - m_editors[m_input_mode]->cursorDown (); -} - -inline void -BopomofoEngine::showSetupDialog (void) -{ - g_spawn_command_line_async (LIBEXECDIR"/ibus-setup-pinyin bopomofo", NULL); -} - -gboolean -BopomofoEngine::propertyActivate (const gchar *prop_name, guint prop_state) -{ - const static std::string setup ("setup"); - if (m_props.propertyActivate (prop_name, prop_state)) { - return TRUE; - } - else if (setup == prop_name) { - showSetupDialog (); - return TRUE; - } - return FALSE; -} - -void -BopomofoEngine::candidateClicked (guint index, guint button, guint state) -{ - m_editors[m_input_mode]->candidateClicked (index, button, state); -} - -void -BopomofoEngine::commitText (Text & text) -{ - Engine::commitText (text); - if (m_input_mode != MODE_INIT) - m_input_mode = MODE_INIT; - if (text.text ()) - static_cast (m_fallback_editor.get ())->setPrevCommittedChar (*text.text ()); - else - static_cast (m_fallback_editor.get ())->setPrevCommittedChar (0); -} - -void -BopomofoEngine::connectEditorSignals (EditorPtr editor) -{ - editor->signalCommitText ().connect ( - std::bind (&BopomofoEngine::commitText, this, _1)); - - editor->signalUpdatePreeditText ().connect ( - std::bind (&BopomofoEngine::updatePreeditText, this, _1, _2, _3)); - editor->signalShowPreeditText ().connect ( - std::bind (&BopomofoEngine::showPreeditText, this)); - editor->signalHidePreeditText ().connect ( - std::bind (&BopomofoEngine::hidePreeditText, this)); - - editor->signalUpdateAuxiliaryText ().connect ( - std::bind (&BopomofoEngine::updateAuxiliaryText, this, _1, _2)); - editor->signalShowAuxiliaryText ().connect ( - std::bind (&BopomofoEngine::showAuxiliaryText, this)); - editor->signalHideAuxiliaryText ().connect ( - std::bind (&BopomofoEngine::hideAuxiliaryText, this)); - - editor->signalUpdateLookupTable ().connect ( - std::bind (&BopomofoEngine::updateLookupTable, this, _1, _2)); - editor->signalUpdateLookupTableFast ().connect ( - std::bind (&BopomofoEngine::updateLookupTableFast, this, _1, _2)); - editor->signalShowLookupTable ().connect ( - std::bind (&BopomofoEngine::showLookupTable, this)); - editor->signalHideLookupTable ().connect ( - std::bind (&BopomofoEngine::hideLookupTable, this)); -} - -}; - diff --git a/src/PYBopomofoEngine.h b/src/PYBopomofoEngine.h deleted file mode 100644 index a99dc83..0000000 --- a/src/PYBopomofoEngine.h +++ /dev/null @@ -1,82 +0,0 @@ -/* vim:set et ts=4 sts=4: - * - * ibus-pinyin - The Chinese PinYin engine for IBus - * - * Copyright (c) 2008-2010 Peng Huang - * Copyright (c) 2010 BYVoid - * - * This program is free software; you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation; either version 2, or (at your option) - * any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program; if not, write to the Free Software - * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. - */ -#ifndef __PY_BOPOMOFO_ENGINE_H_ -#define __PY_BOPOMOFO_ENGINE_H_ - -#include "PYEngine.h" -#include "PYPinyinProperties.h" - -namespace PY { - -class BopomofoEngine : public Engine { -public: - BopomofoEngine (IBusEngine *engine); - ~BopomofoEngine (void); - - // virtual functions - gboolean processKeyEvent (guint keyval, guint keycode, guint modifiers); - void focusIn (void); - void focusOut (void); - void reset (void); - void enable (void); - void disable (void); - void pageUp (void); - void pageDown (void); - void cursorUp (void); - void cursorDown (void); - gboolean propertyActivate (const gchar *prop_name, guint prop_state); - void candidateClicked (guint index, guint button, guint state); - -private: - gboolean processPunct (guint keyval, guint keycode, guint modifiers); - -private: - void showSetupDialog (void); - void connectEditorSignals (EditorPtr editor); - -private: - void commitText (Text & text); - -private: - PinyinProperties m_props; - - guint m_prev_pressed_key; - - enum { - MODE_INIT = 0, // init mode - MODE_PUNCT, // punct mode - MODE_RAW, // raw mode - #if 0 - MODE_ENGLISH, // press v into English input mode - MODE_STROKE, // press u into stroke input mode - #endif - MODE_EXTENSION, // press i into extension input mode - MODE_LAST, - } m_input_mode; - - EditorPtr m_editors[MODE_LAST]; - EditorPtr m_fallback_editor; -}; - -}; - -#endif diff --git a/src/PYDoublePinyinEditor.cc b/src/PYDoublePinyinEditor.cc deleted file mode 100644 index fb775d9..0000000 --- a/src/PYDoublePinyinEditor.cc +++ /dev/null @@ -1,489 +0,0 @@ -/* vim:set et ts=4 sts=4: - * - * ibus-pinyin - The Chinese PinYin engine for IBus - * - * Copyright (c) 2008-2010 Peng Huang - * - * This program is free software; you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation; either version 2, or (at your option) - * any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program; if not, write to the Free Software - * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. - */ -#include "PYDoublePinyinEditor.h" -#include "PYConfig.h" - -namespace PY { - -#define DEFINE_DOUBLE_PINYIN_TABLES -#include "PYDoublePinyinTable.h" - -/* - * 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')) - -DoublePinyinEditor::DoublePinyinEditor (PinyinProperties & props, Config & config) - : PinyinEditor (props, config) -{ -} - -gboolean -DoublePinyinEditor::insert (gint ch) -{ - gint id; - /* is full */ - if (G_UNLIKELY (m_text.length () >= MAX_PINYIN_LEN)) - return TRUE; - - id = ID (ch); - if (id == -1) { - /* it is not availidate ch */ - return FALSE; - } - - if (G_UNLIKELY (m_text.empty () && - ID_TO_SHENG (id) == PINYIN_ID_VOID)) { - return FALSE; - } - - m_text.insert (m_cursor++, ch); - - if (m_cursor > m_pinyin_len + 2 || updatePinyin (FALSE) == FALSE) { - if (!IS_ALPHA (ch)) { - m_text.erase (--m_cursor, 1); - return FALSE; - } - else { - if (updateSpecialPhrases ()) { - update (); - } - else { - updatePreeditText (); - updateAuxiliaryText (); - } - return TRUE; - } - } - else { - updateSpecialPhrases (); - updatePhraseEditor (); - update (); - return TRUE; - } -} - -gboolean -DoublePinyinEditor::removeCharBefore (void) -{ - if (G_UNLIKELY (m_cursor == 0)) - return FALSE; - - m_cursor --; - m_text.erase (m_cursor, 1); - - if (updatePinyin (FALSE)) { - updateSpecialPhrases (); - updatePhraseEditor (); - update (); - } - else { - if (updateSpecialPhrases ()) { - update (); - } - else { - updatePreeditText (); - updateAuxiliaryText (); - } - } - return TRUE; -} - -gboolean -DoublePinyinEditor::removeCharAfter (void) -{ - if (G_UNLIKELY (m_cursor == m_text.length ())) - return FALSE; - - m_text.erase (m_cursor, 1); - if (updateSpecialPhrases ()) { - update (); - } - else { - updatePreeditText (); - updateAuxiliaryText (); - } - return TRUE; -} - -gboolean -DoublePinyinEditor::removeWordBefore (void) -{ - if (G_UNLIKELY (m_cursor == 0)) - return FALSE; - - if (G_UNLIKELY (m_cursor > m_pinyin_len)) { - m_text.erase (m_pinyin_len, m_cursor - m_pinyin_len); - m_cursor = m_pinyin_len; - if (updateSpecialPhrases ()) { - update (); - } - else { - updatePreeditText (); - updateAuxiliaryText (); - } - } - else { - m_pinyin_len = m_pinyin.back ().begin; - m_pinyin.pop_back (); - m_text.erase (m_pinyin_len, m_cursor - m_pinyin_len); - m_cursor = m_pinyin_len; - updateSpecialPhrases (); - updatePhraseEditor (); - update (); - } - - return TRUE; -} - -gboolean -DoublePinyinEditor::removeWordAfter (void) -{ - if (G_UNLIKELY (m_cursor == m_text.length ())) - return FALSE; - - m_text.erase (m_cursor); - if (updateSpecialPhrases ()) { - update (); - } - else { - updatePreeditText (); - updateAuxiliaryText (); - } - return TRUE; -} - -gboolean -DoublePinyinEditor::moveCursorLeft (void) -{ - if (G_UNLIKELY (m_cursor == 0)) - return FALSE; - - m_cursor --; - - if (m_cursor >= m_pinyin_len) { - if (updateSpecialPhrases ()) { - update (); - } - else { - updatePreeditText (); - updateAuxiliaryText (); - } - } - else { - if (updatePinyin (FALSE)) { - updateSpecialPhrases (); - updatePhraseEditor (); - update (); - } - else { - if (updateSpecialPhrases ()) { - update (); - } - else { - updatePreeditText (); - updateAuxiliaryText (); - } - } - } - - return TRUE; -} - -gboolean -DoublePinyinEditor::moveCursorRight (void) -{ - if (G_UNLIKELY (m_cursor == m_text.length ())) - return FALSE; - - m_cursor ++; - if (updatePinyin (FALSE)) { - updateSpecialPhrases (); - updatePhraseEditor (); - update (); - } - else { - if (updateSpecialPhrases ()) { - update (); - } - else { - updatePreeditText (); - updateAuxiliaryText (); - } - } - return TRUE; -} - -gboolean -DoublePinyinEditor::moveCursorLeftByWord (void) -{ - if (G_UNLIKELY (m_cursor == 0)) - return FALSE; - - if (G_UNLIKELY (m_cursor > m_pinyin_len)) { - m_cursor = m_pinyin_len; - if (updateSpecialPhrases ()) { - update (); - } - else { - updatePreeditText (); - updateAuxiliaryText (); - } - } - else { - m_cursor = m_pinyin_len = m_pinyin.back ().begin; - m_pinyin.pop_back (); - updateSpecialPhrases (); - updatePhraseEditor (); - update (); - } - - return TRUE; -} - -gboolean -DoublePinyinEditor::moveCursorRightByWord (void) -{ - return moveCursorToEnd (); -} - -gboolean -DoublePinyinEditor::moveCursorToBegin (void) -{ - if (G_UNLIKELY (m_cursor == 0)) - return FALSE; - - m_cursor = 0; - m_pinyin.clear (); - m_pinyin_len = 0; - updateSpecialPhrases (); - updatePhraseEditor (); - update (); - - return TRUE; -} - -gboolean -DoublePinyinEditor::moveCursorToEnd (void) -{ - if (G_UNLIKELY (m_cursor == m_text.length ())) - return FALSE; - - m_cursor = m_text.length (); - if (updatePinyin (FALSE)) { - updateSpecialPhrases (); - updatePhraseEditor (); - update (); - } - else { - if (updateSpecialPhrases ()) { - update (); - } - else { - updatePreeditText (); - updateAuxiliaryText (); - } - } - return TRUE; -} - -void -DoublePinyinEditor::reset (void) -{ - PinyinEditor::reset (); -} - -inline const Pinyin * -DoublePinyinEditor::isPinyin (gint i) -{ - if ((m_config.option () & PINYIN_INCOMPLETE_PINYIN) == 0) { - return NULL; - } - - gint8 sheng = ID_TO_SHENG (i); - - if (sheng == PINYIN_ID_VOID) { - return NULL; - } - - return PinyinParser::isPinyin (sheng, 0, PINYIN_INCOMPLETE_PINYIN); -} - -inline const Pinyin * -DoublePinyinEditor::isPinyin (gint i, gint j) -{ - const Pinyin *pinyin; - gint8 sheng = ID_TO_SHENG (i); - const gint8 *yun = ID_TO_YUNS (j); - - if (sheng == PINYIN_ID_VOID || yun[0] == PINYIN_ID_VOID) - return NULL; - - if (sheng == PINYIN_ID_ZERO && yun[0] == PINYIN_ID_ZERO) - return NULL; - - if (yun[1] == PINYIN_ID_VOID) { - return PinyinParser::isPinyin (sheng, yun[0], - m_config.option () & (PINYIN_FUZZY_ALL | PINYIN_CORRECT_V_TO_U)); - } - - pinyin = PinyinParser::isPinyin (sheng, yun[0], - m_config.option () & (PINYIN_FUZZY_ALL)); - if (pinyin == NULL) - pinyin = PinyinParser::isPinyin (sheng, yun[1], - m_config.option () & (PINYIN_FUZZY_ALL)); - if (pinyin != NULL) - return pinyin; - - /* if sheng == j q x y and yun == v, try to correct v to u */ - if ((m_config.option () & PINYIN_CORRECT_V_TO_U) == 0) - return NULL; - - if (yun[0] != PINYIN_ID_V && yun[1] != PINYIN_ID_V) - return NULL; - - switch (sheng) { - case PINYIN_ID_J: - case PINYIN_ID_Q: - case PINYIN_ID_X: - case PINYIN_ID_Y: - return PinyinParser::isPinyin (sheng, PINYIN_ID_V, - m_config.option () & (PINYIN_FUZZY_ALL | PINYIN_CORRECT_V_TO_U)); - default: - return NULL; - } -} - -inline gboolean -DoublePinyinEditor::updatePinyin (gboolean all) -{ - gboolean retval = FALSE; - - if (all && - (m_pinyin_len != 0 || !m_pinyin.empty ())) { - m_pinyin.clear (); - m_pinyin_len = 0; - retval = TRUE; - } - - if (m_pinyin_len > m_cursor) { - retval = TRUE; - while (m_pinyin_len > m_cursor) { - m_pinyin_len = m_pinyin.back ().begin; - m_pinyin.pop_back (); - } - } - - if (m_pinyin_len == m_cursor) { - return retval; - } - - if (m_pinyin_len < m_cursor) { - guint len = m_pinyin_len; - if (m_pinyin.empty () == FALSE && - m_pinyin.back ()->flags & PINYIN_INCOMPLETE_PINYIN) { - const Pinyin *pinyin = isPinyin (ID (m_text[m_pinyin_len -1]),ID (m_text[m_pinyin_len])); - if (pinyin) { - m_pinyin.pop_back (); - m_pinyin.append (pinyin, m_pinyin_len - 1, 2); - m_pinyin_len += 1; - } - } - while (m_pinyin_len < m_cursor && m_pinyin.size () < MAX_PHRASE_LEN) { - const Pinyin *pinyin = NULL; - if (m_pinyin_len == m_cursor - 1) { - pinyin = isPinyin (ID (m_text[m_pinyin_len])); - } - else { - pinyin = isPinyin (ID (m_text[m_pinyin_len]), ID (m_text[m_pinyin_len + 1])); - if (pinyin == NULL) - pinyin = isPinyin (ID (m_text[m_pinyin_len])); - } - if (pinyin == NULL) - break; - if (pinyin->flags & PINYIN_INCOMPLETE_PINYIN) { - m_pinyin.append (pinyin, m_pinyin_len, 1); - m_pinyin_len += 1; - } - else { - m_pinyin.append (pinyin, m_pinyin_len, 2); - m_pinyin_len += 2; - } - } - if (len == m_pinyin_len) - return retval; - return TRUE; - } - return retval; -} - -void -DoublePinyinEditor::updateAuxiliaryTextAfter (String &buffer) -{ - if (G_LIKELY (!m_config.doublePinyinShowRaw ())) - return; - - if (G_LIKELY (m_config.orientation () == IBUS_ORIENTATION_HORIZONTAL)) { - buffer << " [ "; - } - else { - buffer << "\n[ "; - } - - if (G_LIKELY (m_cursor == m_text.length ())) { - m_buffer << m_text << " ]"; - } - else { - buffer.append (m_text.c_str (), m_cursor); - buffer << " "; - buffer.append (m_text.c_str () + m_cursor); - buffer << " ]"; - } -} - -gboolean -DoublePinyinEditor::processKeyEvent (guint keyval, guint keycode, guint modifiers) -{ - /* handle ';' key */ - if (G_UNLIKELY (keyval == IBUS_semicolon)) { - if (cmshm_filter (modifiers) == 0) { - if (insert (keyval)) - return TRUE; - } - } - - return PinyinEditor::processKeyEvent (keyval, keycode, modifiers); -} - -}; - - diff --git a/src/PYDoublePinyinEditor.h b/src/PYDoublePinyinEditor.h deleted file mode 100644 index e9ef1e9..0000000 --- a/src/PYDoublePinyinEditor.h +++ /dev/null @@ -1,63 +0,0 @@ -/* vim:set et ts=4 sts=4: - * - * ibus-pinyin - The Chinese PinYin engine for IBus - * - * Copyright (c) 2008-2010 Peng Huang - * - * This program is free software; you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation; either version 2, or (at your option) - * any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program; if not, write to the Free Software - * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. - */ -#ifndef __PY_DOUBLE_PINYIN_EDITOR_H_ -#define __PY_DOUBLE_PINYIN_EDITOR_H_ - -#include "PYPinyinEditor.h" - -namespace PY { - -class DoublePinyinEditor : public PinyinEditor { - -public: - DoublePinyinEditor (PinyinProperties & props, Config & config); - - gboolean insert (gint ch); - - gboolean removeCharBefore (void); - gboolean removeCharAfter (void); - gboolean removeWordBefore (void); - gboolean removeWordAfter (void); - - gboolean moveCursorLeft (void); - gboolean moveCursorRight (void); - gboolean moveCursorLeftByWord (void); - gboolean moveCursorRightByWord (void); - gboolean moveCursorToBegin (void); - gboolean moveCursorToEnd (void); - - /* override virtual functions */ - gboolean processKeyEvent (guint keyval, guint keycode, guint modifiers); - void reset (void); - void updateAuxiliaryTextAfter (String &buffer); - -protected: - gboolean updatePinyin (gboolean all); - -private: - const Pinyin *isPinyin (gint i, gint j); - const Pinyin *isPinyin (gint i); - -}; - -}; - -#endif diff --git a/src/PYFullPinyinEditor.cc b/src/PYFullPinyinEditor.cc deleted file mode 100644 index 4530395..0000000 --- a/src/PYFullPinyinEditor.cc +++ /dev/null @@ -1,241 +0,0 @@ -/* vim:set et ts=4 sts=4: - * - * ibus-pinyin - The Chinese PinYin engine for IBus - * - * Copyright (c) 2008-2010 Peng Huang - * - * This program is free software; you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation; either version 2, or (at your option) - * any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program; if not, write to the Free Software - * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. - */ -#include "PYFullPinyinEditor.h" -#include "PYConfig.h" - -namespace PY { - -FullPinyinEditor::FullPinyinEditor (PinyinProperties & props, Config & config) - : PinyinEditor (props, config) -{ -} - -FullPinyinEditor::~FullPinyinEditor (void) -{ -} - -void -FullPinyinEditor::reset (void) -{ - PinyinEditor::reset (); -} - -gboolean -FullPinyinEditor::insert (gint ch) -{ - /* is full */ - if (G_UNLIKELY (m_text.length () >= MAX_PINYIN_LEN)) - return TRUE; - - m_text.insert (m_cursor++, ch); - - if (G_UNLIKELY (!(m_config.option () & PINYIN_INCOMPLETE_PINYIN))) { - updateSpecialPhrases (); - updatePinyin (); - } - else if (G_LIKELY (m_cursor <= m_pinyin_len + 2)) { - updateSpecialPhrases (); - updatePinyin (); - } - else { - if (updateSpecialPhrases ()) { - update (); - } - else { - updatePreeditText (); - updateAuxiliaryText (); - } - } - return TRUE; -} - -gboolean -FullPinyinEditor::removeCharBefore (void) -{ - if (G_UNLIKELY (m_cursor == 0)) - return FALSE; - - m_cursor --; - m_text.erase (m_cursor, 1); - - updateSpecialPhrases (); - updatePinyin (); - - return TRUE; -} - -gboolean -FullPinyinEditor::removeCharAfter (void) -{ - if (G_UNLIKELY (m_cursor == m_text.length ())) - return FALSE; - - m_text.erase (m_cursor, 1); - updatePreeditText (); - updateAuxiliaryText (); - - return TRUE; -} - -gboolean -FullPinyinEditor::removeWordBefore (void) -{ - if (G_UNLIKELY (m_cursor == 0)) - return FALSE; - - guint cursor; - - if (G_UNLIKELY (m_cursor > m_pinyin_len)) { - cursor = m_pinyin_len; - } - else { - const Pinyin & p = *m_pinyin.back (); - cursor = m_cursor - p.len; - m_pinyin_len -= p.len; - m_pinyin.pop_back (); - } - - m_text.erase (cursor, m_cursor - cursor); - m_cursor = cursor; - updateSpecialPhrases (); - updatePhraseEditor (); - update (); - return TRUE; -} - -gboolean -FullPinyinEditor::removeWordAfter (void) -{ - if (G_UNLIKELY (m_cursor == m_text.length ())) - return FALSE; - - m_text.erase (m_cursor, -1); - updatePreeditText (); - updateAuxiliaryText (); - return TRUE; -} - -gboolean -FullPinyinEditor::moveCursorLeft (void) -{ - if (G_UNLIKELY (m_cursor == 0)) - return FALSE; - - m_cursor --; - updateSpecialPhrases (); - updatePinyin (); - - return TRUE; -} - -gboolean -FullPinyinEditor::moveCursorRight (void) -{ - if (G_UNLIKELY (m_cursor == m_text.length ())) - return FALSE; - - m_cursor ++; - - updateSpecialPhrases (); - updatePinyin (); - - return TRUE; -} - -gboolean -FullPinyinEditor::moveCursorLeftByWord (void) -{ - if (G_UNLIKELY (m_cursor == 0)) - return FALSE; - - if (G_UNLIKELY (m_cursor > m_pinyin_len)) { - m_cursor = m_pinyin_len; - return TRUE; - } - - const Pinyin & p = *m_pinyin.back (); - m_cursor -= p.len; - m_pinyin_len -= p.len; - m_pinyin.pop_back (); - - updateSpecialPhrases (); - updatePhraseEditor (); - update (); - - return TRUE; -} - -gboolean -FullPinyinEditor::moveCursorRightByWord (void) -{ - return moveCursorToEnd (); -} - -gboolean -FullPinyinEditor::moveCursorToBegin (void) -{ - if (G_UNLIKELY (m_cursor == 0)) - return FALSE; - - m_cursor = 0; - m_pinyin.clear (); - m_pinyin_len = 0; - - updateSpecialPhrases (); - updatePhraseEditor (); - update (); - - return TRUE; -} - -gboolean -FullPinyinEditor::moveCursorToEnd (void) -{ - if (G_UNLIKELY (m_cursor == m_text.length ())) - return FALSE; - - m_cursor = m_text.length (); - updateSpecialPhrases (); - updatePinyin (); - - return TRUE; -} - -void -FullPinyinEditor::updatePinyin (void) -{ - if (G_UNLIKELY (m_text.empty ())) { - m_pinyin.clear (); - m_pinyin_len = 0; - } - else { - m_pinyin_len = PinyinParser::parse (m_text, // text - m_cursor, // text length - m_config.option (), // option - m_pinyin, // result - MAX_PHRASE_LEN); // max result length - } - - updatePhraseEditor (); - update (); -} - -}; diff --git a/src/PYFullPinyinEditor.h b/src/PYFullPinyinEditor.h deleted file mode 100644 index aba2077..0000000 --- a/src/PYFullPinyinEditor.h +++ /dev/null @@ -1,64 +0,0 @@ -/* vim:set et ts=4 sts=4: - * - * ibus-pinyin - The Chinese PinYin engine for IBus - * - * Copyright (c) 2008-2010 Peng Huang - * - * This program is free software; you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation; either version 2, or (at your option) - * any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program; if not, write to the Free Software - * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. - */ -#ifndef __PY_FULL_PINYIN_EDITOR_H_ -#define __PY_FULL_PINYIN_EDITOR_H_ - -#include "PYPinyinEditor.h" - -namespace PY { - -class Config; - -class FullPinyinEditor : public PinyinEditor { - -public: - FullPinyinEditor (PinyinProperties & props, Config & config); - ~FullPinyinEditor (void); - -public: - /* virtual functions */ -#if 0 - virtual gboolean processKeyEvent (guint keyval, guint keycode, guint modifiers); -#endif - virtual void reset (void); - -protected: - gboolean insert (gint ch); - - gboolean removeCharBefore (void); - gboolean removeCharAfter (void); - gboolean removeWordBefore (void); - gboolean removeWordAfter (void); - - gboolean moveCursorLeft (void); - gboolean moveCursorRight (void); - gboolean moveCursorLeftByWord (void); - gboolean moveCursorRightByWord (void); - gboolean moveCursorToBegin (void); - gboolean moveCursorToEnd (void); - - void updatePinyin (void); - -}; - -}; - -#endif -- 2.7.4