diff options
Diffstat (limited to 'src')
-rw-r--r-- | src/ZYConfig.cc | 4 | ||||
-rw-r--r-- | src/ZYConfig.h | 8 | ||||
-rw-r--r-- | src/ZYLibZhuyin.cc | 17 | ||||
-rw-r--r-- | src/ZYZConfig.cc | 62 | ||||
-rw-r--r-- | src/ZYZZhuyinEngine.cc | 31 | ||||
-rw-r--r-- | src/ZYZZhuyinEngine.h | 2 |
6 files changed, 73 insertions, 51 deletions
diff --git a/src/ZYConfig.cc b/src/ZYConfig.cc index 4686dbe..f8b965b 100644 --- a/src/ZYConfig.cc +++ b/src/ZYConfig.cc @@ -46,7 +46,9 @@ Config::initDefaultValues (void) { m_page_size = 5; - m_keyboard_layout = CHEWING_DEFAULT; + m_is_zhuyin = TRUE; + m_zhuyin_scheme = ZHUYIN_DEFAULT; + m_pinyin_scheme = FULL_PINYIN_DEFAULT; m_init_chinese = TRUE; m_init_full_width = FALSE; diff --git a/src/ZYConfig.h b/src/ZYConfig.h index 8745061..ae28efa 100644 --- a/src/ZYConfig.h +++ b/src/ZYConfig.h @@ -44,7 +44,9 @@ public: zhuyin_option_t option (void) const { return m_option & m_option_mask; } guint orientation (void) const { return m_orientation; } guint pageSize (void) const { return m_page_size; } - ZhuyinScheme keyboardLayout (void) const { return m_keyboard_layout; } + gboolean isZhuyin(void) const { return m_is_zhuyin; } + ZhuyinScheme zhuyinScheme (void) const { return m_zhuyin_scheme; } + FullPinyinScheme pinyinScheme (void) const { return m_pinyin_scheme; } gboolean initChinese (void) const { return m_init_chinese; } gboolean initFullWidth (void) const { return m_init_full_width; } gboolean initTradChinese (void) const { return m_init_trad_chinese; } @@ -81,7 +83,9 @@ protected: gint m_orientation; guint m_page_size; - ZhuyinScheme m_keyboard_layout; + gboolean m_is_zhuyin; + ZhuyinScheme m_zhuyin_scheme; + FullPinyinScheme m_pinyin_scheme; gboolean m_init_chinese; gboolean m_init_full_width; diff --git a/src/ZYLibZhuyin.cc b/src/ZYLibZhuyin.cc index f6bc01a..3d2084b 100644 --- a/src/ZYLibZhuyin.cc +++ b/src/ZYLibZhuyin.cc @@ -78,17 +78,12 @@ LibZhuyinBackEnd::setZhuyinOptions (Config *config) if (NULL == m_zhuyin_context) return FALSE; - ZhuyinScheme scheme = config->keyboardLayout (); - switch (scheme) { - case CHEWING_STANDARD ... CHEWING_DACHEN_CP26: - zhuyin_set_chewing_scheme (m_zhuyin_context, scheme); - break; - case FULL_PINYIN_HANYU ... FULL_PINYIN_SECONDARY_BOPOMOFO: - zhuyin_set_full_pinyin_scheme (m_zhuyin_context, scheme); - break; - default: - assert (FALSE); - } + if (config->isZhuyin ()) + zhuyin_set_chewing_scheme (m_zhuyin_context, + config->zhuyinScheme ()); + else + zhuyin_set_full_pinyin_scheme (m_zhuyin_context, + config->pinyinScheme ()); zhuyin_option_t options = config->option (); zhuyin_set_options (m_zhuyin_context, options); diff --git a/src/ZYZConfig.cc b/src/ZYZConfig.cc index 8d646e9..40facad 100644 --- a/src/ZYZConfig.cc +++ b/src/ZYZConfig.cc @@ -87,7 +87,9 @@ ZhuyinConfig::initDefaultValues (void) m_orientation = IBUS_ORIENTATION_VERTICAL; m_page_size = 10; - m_keyboard_layout = CHEWING_DEFAULT; + m_is_zhuyin = TRUE; + m_zhuyin_scheme = ZHUYIN_DEFAULT; + m_pinyin_scheme = FULL_PINYIN_DEFAULT; m_init_chinese = TRUE; m_init_full_width = FALSE; @@ -108,18 +110,24 @@ static const struct { gint layout; ZhuyinScheme scheme; } zhuyin_schemes [] = { - {0, CHEWING_STANDARD}, - {1, CHEWING_HSU}, - {2, CHEWING_IBM}, - {3, CHEWING_GINYIEH}, - {4, CHEWING_ETEN}, - {5, CHEWING_ETEN26}, - {6, CHEWING_STANDARD_DVORAK}, - {7, CHEWING_HSU_DVORAK}, - {8, CHEWING_DACHEN_CP26}, + {0, ZHUYIN_STANDARD}, + {1, ZHUYIN_HSU}, + {2, ZHUYIN_IBM}, + {3, ZHUYIN_GINYIEH}, + {4, ZHUYIN_ETEN}, + {5, ZHUYIN_ETEN26}, + {6, ZHUYIN_STANDARD_DVORAK}, + {7, ZHUYIN_HSU_DVORAK}, + {8, ZHUYIN_DACHEN_CP26}, +}; + +static const struct { + gint layout; + FullPinyinScheme scheme; +} pinyin_schemes [] = { {9, FULL_PINYIN_HANYU}, {10, FULL_PINYIN_LUOMA}, - {11, FULL_PINYIN_SECONDARY_BOPOMOFO}, + {11, FULL_PINYIN_SECONDARY_ZHUYIN}, }; static const struct { @@ -190,11 +198,22 @@ ZhuyinConfig::readDefaultValues (void) m_candidates_after_cursor = read (CONFIG_CANDIDATES_AFTER_CURSOR, true); gint layout = read (CONFIG_KEYBOARD_LAYOUT, 0); - m_keyboard_layout = CHEWING_DEFAULT; + + m_is_zhuyin = TRUE; + m_zhuyin_scheme = ZHUYIN_DEFAULT; + m_pinyin_scheme = FULL_PINYIN_DEFAULT; + + for (guint i = 0; i < G_N_ELEMENTS (pinyin_schemes); ++i) { + if (pinyin_schemes[i].layout == layout) { + m_is_zhuyin = FALSE; + m_pinyin_scheme = pinyin_schemes[i].scheme; + } + } for (guint i = 0; i < G_N_ELEMENTS (zhuyin_schemes); ++i) { if (zhuyin_schemes[i].layout == layout) { - m_keyboard_layout = zhuyin_schemes[i].scheme; + m_is_zhuyin = TRUE; + m_zhuyin_scheme = zhuyin_schemes[i].scheme; } } @@ -247,12 +266,23 @@ ZhuyinConfig::valueChanged (const std::string §ion, else if (CONFIG_CANDIDATES_AFTER_CURSOR == name) m_candidates_after_cursor = normalizeGVariant (value, true); else if (CONFIG_KEYBOARD_LAYOUT == name) { - gint layout = normalizeGVariant (value, 0); - m_keyboard_layout = CHEWING_DEFAULT; + gint layout = read (CONFIG_KEYBOARD_LAYOUT, 0); + + m_is_zhuyin = TRUE; + m_zhuyin_scheme = ZHUYIN_DEFAULT; + m_pinyin_scheme = FULL_PINYIN_DEFAULT; + + for (guint i = 0; i < G_N_ELEMENTS (pinyin_schemes); ++i) { + if (pinyin_schemes[i].layout == layout) { + m_is_zhuyin = FALSE; + m_pinyin_scheme = pinyin_schemes[i].scheme; + } + } for (guint i = 0; i < G_N_ELEMENTS (zhuyin_schemes); ++i) { if (zhuyin_schemes[i].layout == layout) { - m_keyboard_layout = zhuyin_schemes[i].scheme; + m_is_zhuyin = TRUE; + m_zhuyin_scheme = zhuyin_schemes[i].scheme; } } } else if (CONFIG_CANDIDATE_KEYS == name) { diff --git a/src/ZYZZhuyinEngine.cc b/src/ZYZZhuyinEngine.cc index fae5e0b..afd26d4 100644 --- a/src/ZYZZhuyinEngine.cc +++ b/src/ZYZZhuyinEngine.cc @@ -43,20 +43,14 @@ ZhuyinEngine::ZhuyinEngine (IBusEngine *engine) { gint i; - m_zhuyin_scheme = ZhuyinConfig::instance ().keyboardLayout (); + Config *config = &ZhuyinConfig::instance (); - switch (m_zhuyin_scheme) { - case CHEWING_STANDARD ... CHEWING_DACHEN_CP26: + if (config->isZhuyin ()) m_editors[MODE_INIT].reset (new ZhuyinEditor (m_props, ZhuyinConfig::instance ())); - break; - case FULL_PINYIN_HANYU ... FULL_PINYIN_SECONDARY_BOPOMOFO: + else m_editors[MODE_INIT].reset (new PinyinEditor (m_props, ZhuyinConfig::instance ())); - break; - default: - assert (FALSE); - } m_editors[MODE_RAW].reset (new RawEditor (m_props, ZhuyinConfig::instance ())); @@ -158,24 +152,21 @@ ZhuyinEngine::processKeyEvent (guint keyval, guint keycode, guint modifiers) void ZhuyinEngine::focusIn (void) { - /* TODO: check memory leak here.*/ - const ZhuyinScheme scheme = ZhuyinConfig::instance ().keyboardLayout (); - if (scheme != m_zhuyin_scheme) { - switch (scheme) { - case CHEWING_STANDARD ... CHEWING_DACHEN_CP26: + Config *config = &ZhuyinConfig::instance (); + + gboolean is_zhuyin = config->isZhuyin (); + if (is_zhuyin != m_is_zhuyin) { + if (config->isZhuyin ()) { m_editors[MODE_INIT].reset (new ZhuyinEditor (m_props, ZhuyinConfig::instance ())); connectEditorSignals (m_editors[MODE_INIT]); - break; - case FULL_PINYIN_HANYU ... FULL_PINYIN_SECONDARY_BOPOMOFO: + } else { m_editors[MODE_INIT].reset (new PinyinEditor (m_props, ZhuyinConfig::instance ())); connectEditorSignals (m_editors[MODE_INIT]); - break; - default: - assert (FALSE); } - m_zhuyin_scheme = scheme; + + m_is_zhuyin = is_zhuyin; } registerProperties (m_props.properties ()); diff --git a/src/ZYZZhuyinEngine.h b/src/ZYZZhuyinEngine.h index 283404f..33a606f 100644 --- a/src/ZYZZhuyinEngine.h +++ b/src/ZYZZhuyinEngine.h @@ -63,7 +63,7 @@ private: MODE_LAST, } m_input_mode; - ZhuyinScheme m_zhuyin_scheme; + gboolean m_is_zhuyin; EditorPtr m_editors[MODE_LAST]; EditorPtr m_fallback_editor; |