1 /*************************************************************************** 2 * Copyright (C) 2010~2011 by CSSlayer * 3 * wengxt@gmail.com * 4 * * 5 * This program is free software; you can redistribute it and/or modify * 6 * it under the terms of the GNU General Public License as published by * 7 * the Free Software Foundation; either version 2 of the License, or * 8 * (at your option) any later version. * 9 * * 10 * This program is distributed in the hope that it will be useful, * 11 * but WITHOUT ANY WARRANTY; without even the implied warranty of * 12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * 13 * GNU General Public License for more details. * 14 * * 15 * You should have received a copy of the GNU General Public License * 16 * along with this program; if not, write to the * 17 * Free Software Foundation, Inc., * 18 * 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA. * 19 ***************************************************************************/ 20 21 #ifndef EIM_H 22 #define EIM_H 23 24 #include <fcitx/ime.h> 25 #include <fcitx-config/fcitx-config.h> 26 #include <fcitx/instance.h> 27 #include <fcitx/candidate.h> 28 #include <pinyin.h> 29 #include <vector> 30 #include <string> 31 #include "bus.h" 32 #include "common.h" 33 34 #define MAX_PINYIN_INPUT 60 35 36 #define _(x) dgettext("fcitx-libpinyin", (x)) 37 38 class FcitxWindowHandler; 39 40 /* 41 * the reason that not using libpinyin enum here 42 * 1. libpinyin seems cannot make enum stable (from their header) 43 * 2. the range is not continuous, so make a translate layer 44 */ 45 enum FCITX_ZHUYIN_LAYOUT { 46 FCITX_ZHUYIN_STANDARD = 0, 47 FCITX_ZHUYIN_IBM = 1, 48 FCITX_ZHUYIN_GIN_YIEH = 2, 49 FCITX_ZHUYIN_ET = 3 50 }; 51 52 enum FCITX_SHUANGPIN_SCHEME { 53 FCITX_SHUANG_PIN_ZRM = 0, 54 FCITX_SHUANG_PIN_MS = 1, 55 FCITX_SHUANG_PIN_ZIGUANG = 2, 56 FCITX_SHUANG_PIN_ABC = 3, 57 FCITX_SHUANG_PIN_PYJJ = 4, 58 FCITX_SHUANG_PIN_XHE = 5 59 }; 60 61 enum FCITX_CORRECTION { 62 FCITX_CR_V_U, 63 FCITX_CR_GN_NG, 64 FCITX_CR_MG_NG, 65 FCITX_CR_IOU_IU, 66 FCITX_CR_UEI_UI, 67 FCITX_CR_UEN_UN, 68 FCITX_CR_UE_VE, 69 FCITX_CR_ON_ONG, 70 FCITX_CR_LAST = FCITX_CR_ON_ONG 71 }; 72 73 enum FCITX_DICTIONARY { 74 FCITX_DICT_ART, 75 FCITX_DICT_CULTURE, 76 FCITX_DICT_ECONOMY, 77 FCITX_DICT_GEOLOGY, 78 FCITX_DICT_HISTORY, 79 FCITX_DICT_LIFE, 80 FCITX_DICT_NATURE, 81 FCITX_DICT_PEOPLE, 82 FCITX_DICT_SCIENCE, 83 FCITX_DICT_SOCIETY, 84 FCITX_DICT_SPORT, 85 FCITX_DICT_TECHNOLOGY, 86 FCITX_DICT_LAST = FCITX_DICT_TECHNOLOGY 87 }; 88 89 enum FCITX_ZHUYIN_DICTIONARY { 90 FCITX_ZHUYIN_DICT_ART, 91 FCITX_ZHUYIN_DICT_CULTURE, 92 FCITX_ZHUYIN_DICT_ECONOMY, 93 FCITX_ZHUYIN_DICT_GEOLOGY, 94 FCITX_ZHUYIN_DICT_HISTORY, 95 FCITX_ZHUYIN_DICT_LIFE, 96 FCITX_ZHUYIN_DICT_NATURE, 97 FCITX_ZHUYIN_DICT_SCITECH, 98 FCITX_ZHUYIN_DICT_SOCIETY, 99 FCITX_ZHUYIN_DICT_SPORT, 100 FCITX_ZHUYIN_DICT_LAST = FCITX_ZHUYIN_DICT_SPORT 101 }; 102 103 enum FCITX_AMBIGUITY { 104 FCITX_AMB_CiChi, 105 FCITX_AMB_ZiZhi, 106 FCITX_AMB_SiShi, 107 FCITX_AMB_LeNe, 108 FCITX_AMB_FoHe, 109 FCITX_AMB_LeRi, 110 FCITX_AMB_GeKe, 111 FCITX_AMB_AnAng, 112 FCITX_AMB_EnEng, 113 FCITX_AMB_InIng, 114 FCITX_AMB_LAST = FCITX_AMB_InIng 115 }; 116 117 enum FCITX_ZHUYIN_MODIFIERS { 118 FZM_Ctrl = 0, 119 FZM_Alt = 1, 120 FZM_Shift = 2, 121 }; 122 123 enum FCITX_LIBPINYIN_SORT { 124 FLS_PhraseLengthAndFreq, 125 FLS_PhraseLengthAndPinyinLengthAndFreq, 126 }; 127 128 struct FcitxLibPinyinConfig 129 { 130 FcitxGenericConfig gconfig; 131 FCITX_ZHUYIN_LAYOUT zhuyinLayout; 132 FCITX_SHUANGPIN_SCHEME spScheme; 133 FCITX_ZHUYIN_MODIFIERS candidateModifiers; 134 FCITX_LIBPINYIN_SORT sort; 135 boolean amb[FCITX_AMB_LAST + 1]; 136 boolean cr[FCITX_CR_LAST + 1]; 137 boolean dict[FCITX_DICT_LAST + 1]; 138 boolean dict_zhuyin[FCITX_ZHUYIN_DICT_LAST + 1]; 139 boolean incomplete; 140 boolean zhuyinIncomplete; 141 boolean bTraditionalDataForPinyin; 142 boolean bSimplifiedDataForZhuyin; 143 boolean useTone; 144 FcitxHotkey hkPrevPage[2]; 145 FcitxHotkey hkNextPage[2]; 146 }; 147 148 #define BUF_SIZE 4096 149 150 CONFIG_BINDING_DECLARE(FcitxLibPinyinConfig); 151 void* FcitxLibPinyinCreate(FcitxInstance* instance); 152 void FcitxLibPinyinDestroy(void* arg); 153 INPUT_RETURN_VALUE FcitxLibPinyinDoInput(void* arg, FcitxKeySym sym, unsigned int state); 154 INPUT_RETURN_VALUE FcitxLibPinyinGetCandWords (void *arg); 155 INPUT_RETURN_VALUE FcitxLibPinyinGetCandWord (void *arg, FcitxCandidateWord* candWord); 156 boolean FcitxLibPinyinInit(void*); 157 void FcitxLibPinyinReloadConfig(void*); 158 159 class FcitxLibPinyin; 160 161 typedef struct _FcitxLibPinyinAddonInstance { 162 FcitxLibPinyinConfig config; 163 164 pinyin_context_t* pinyin_context; 165 pinyin_context_t* zhuyin_context; 166 167 FcitxLibPinyin* pinyin; 168 FcitxLibPinyin* shuangpin; 169 FcitxLibPinyin* zhuyin; 170 FcitxInstance* owner; 171 FcitxLibPinyinBus* bus; 172 } FcitxLibPinyinAddonInstance; 173 174 class FcitxLibPinyin 175 { 176 public: 177 FcitxLibPinyin(FcitxLibPinyinAddonInstance* libpinyinaddon, LIBPINYIN_TYPE type); 178 ~FcitxLibPinyin(); 179 180 void import(); 181 void clearData(int type); 182 183 int offset() const; 184 int pinyinOffset() const; 185 void reset(); 186 size_t parse(const char* str); 187 INPUT_RETURN_VALUE doInput(FcitxKeySym sym, unsigned int state); 188 void load(); 189 INPUT_RETURN_VALUE getCandWords(); 190 INPUT_RETURN_VALUE getCandWord(FcitxCandidateWord* candWord); 191 std::string sentence(guint8 index); 192 void init(); 193 void updatePreedit(const std::string &sentence); 194 void savePinyinWord(const char *str); 195 void save(); 196 197 private: 198 pinyin_instance_t* m_inst; 199 std::vector<std::pair<int, int> > m_fixedString; 200 std::string m_buf; 201 int m_cursorPos; 202 int m_parsedLen; 203 LIBPINYIN_TYPE m_type; 204 FcitxLibPinyinAddonInstance* m_owner; 205 }; 206 207 #endif 208 // kate: indent-mode cstyle; space-indent on; indent-width 0; 209