1 /* 2 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER. 3 * 4 * Copyright (c) 2007 Sun Microsystems, Inc. All Rights Reserved. 5 * 6 * The contents of this file are subject to the terms of either the GNU Lesser 7 * General Public License Version 2.1 only ("LGPL") or the Common Development and 8 * Distribution License ("CDDL")(collectively, the "License"). You may not use this 9 * file except in compliance with the License. You can obtain a copy of the CDDL at 10 * http://www.opensource.org/licenses/cddl1.php and a copy of the LGPLv2.1 at 11 * http://www.opensource.org/licenses/lgpl-license.php. See the License for the 12 * specific language governing permissions and limitations under the License. When 13 * distributing the software, include this License Header Notice in each file and 14 * include the full text of the License in the License file as well as the 15 * following notice: 16 * 17 * NOTICE PURSUANT TO SECTION 9 OF THE COMMON DEVELOPMENT AND DISTRIBUTION LICENSE 18 * (CDDL) 19 * For Covered Software in this distribution, this License shall be governed by the 20 * laws of the State of California (excluding conflict-of-law provisions). 21 * Any litigation relating to this License shall be subject to the jurisdiction of 22 * the Federal Courts of the Northern District of California and the state courts 23 * of the State of California, with venue lying in Santa Clara County, California. 24 * 25 * Contributor(s): 26 * 27 * If you wish your version of this file to be governed by only the CDDL or only 28 * the LGPL Version 2.1, indicate your decision by adding "[Contributor]" elects to 29 * include this software in this distribution under the [CDDL or LGPL Version 2.1] 30 * license." If you don't indicate a single choice of license, a recipient has the 31 * option to distribute your version of this file under either the CDDL or the LGPL 32 * Version 2.1, or to extend the choice of license to its licensees as provided 33 * above. However, if you add LGPL Version 2.1 code and therefore, elected the LGPL 34 * Version 2 license, then the option applies only if the new code is made subject 35 * to such option by the copyright holder. 36 */ 37 38 #ifndef SUNPY_IMI_CLASSIC_VIEW_H 39 #define SUNPY_IMI_CLASSIC_VIEW_H 40 41 #include "portability.h" 42 43 #include "imi_view.h" 44 45 class CIMIClassicView : public CIMIView { 46 public: 47 CIMIClassicView(); 48 49 virtual ~CIMIClassicView(); 50 51 virtual int getViewType(void); 52 53 virtual void attachIC(CIMIContext* pIC); 54 55 virtual unsigned clearIC(void); 56 57 virtual void updateWindows(unsigned int mask); 58 59 virtual int onKeyEvent(unsigned keycode, unsigned keyvalue, unsigned modifier); 60 61 virtual int onCandidatePageRequest(int pgno, bool relative); 62 63 virtual int onCandidateSelectRequest(int index); 64 65 /*@{*/ 66 /** 67 * get preedit, where from the beginning of the skeleton to the m_candiBone, 68 * give the best converted HANZI string. from the m_candiBone (include) to 69 * the end of the skeleton, give the original PINYIN string. 70 */ 71 virtual void getPreeditString(IPreeditString& ps); 72 73 virtual void getCandidateList(ICandidateList& cl, int start, int size); 74 /*@}*/ 75 76 77 protected: 78 void 79 pressNormalKey(unsigned keyvalue, unsigned int& mask); 80 81 /** 82 * Select the idx-th candidate on user's request. move the current 83 * Bone forwards to next bone, re-get candidate list. So, all 84 * window area (preedit and candidate window) should be update 85 */ 86 void 87 makeSelection(int idx, unsigned int& mask); 88 89 90 /*@{*/ 91 /** 92 * Note only left direction move would cause human selection be discarded 93 * @return: the leftmost bone iterator after operation from which 94 * the new search should begin. If searchAgain = false, 95 * should call explictly to: 96 * m_pIC->searchFrom(leftmost) 97 * value m_pIC->getLastBone() indicat no search are needed or done! 98 */ 99 CSkeletonIter 100 moveLeft(unsigned int& mask, bool searchAgain=true); 101 102 CSkeletonIter 103 moveLeftSyllable(unsigned int& mask, bool searchAgain=true); 104 105 CSkeletonIter 106 moveHome(unsigned int& mask, bool searchAgain=true); 107 108 void 109 moveRight(unsigned int& mask); 110 111 void 112 moveRightSyllable(unsigned int& mask); 113 114 void 115 moveEnd(unsigned int& mask); 116 /*@}*/ 117 118 /*@{*/ 119 /** 120 * Erase a character near current cursor on the preedit area 121 * @param bLeft: true to erase left char beside cursor. 122 * false to erase right char beside cursor. 123 * @param mask: which area should be update after this operation. 124 */ 125 void 126 erase(bool bLeft, unsigned int& mask); 127 128 /** 129 * Insert a Pinyin character right before the cursor. 130 * @param keyvalue: the Pinyin Char to be inserted before cursor. 131 * @param mask: which area should be update after this operation. 132 */ 133 void 134 insertPinyin(unsigned int keyvalue, unsigned int& mask); 135 136 /** 137 * Insert a normal character at the cursor. 138 * @param boneType: NODE_ASCII or NODE_PUNC 139 * @param keyvalue: the normal char to be inserted, must in [0x20,0x7e]. 140 * @param mask : which area should be update after this operation. 141 */ 142 void 143 insertNormalChar(int boneType, unsigned orig_value, unsigned keyvalue, unsigned int& mask); 144 145 /** 146 * Insert human boundary to current cursor on the preedit area, or change 147 * the old boundary at cursor from auto boundary to human boundary. 148 * @param mask: which area should be update after this operation. 149 */ 150 void 151 insertBoundary(unsigned int& mask); 152 /*@}*/ 153 154 /*@{*/ 155 /** 156 * commit whole sentence to user. 157 * @param bConvert: true to commit the converted HANZI string. 158 * false to commit the unconverted PINYIN string. 159 */ 160 void 161 doCommit(bool bConvert=true); 162 163 /** commit single character to user, only when skeleton is empty */ 164 void 165 commitChar(TWCHAR ch); 166 167 /** 168 * get best sentence from itStart to the end of the skeleton. 169 * @param itStart: the starting bone from which convertion starts 170 * @param wstr: the HANZI string of the convertion 171 * @return : the number of converted words in the wstr string.(ie. do not count 172 * non-pinyin node's result. 173 */ 174 int 175 getSentence(wstring& wstr, CSkeletonIter itStart); 176 /*@}*/ 177 178 private: 179 /** the bone under the cursor */ 180 CSkeletonIter m_CursorBone; 181 182 /** cursor position inside the bone */ 183 int m_CursorIdx; 184 185 /** the candidate-list's starting bone. */ 186 CSkeletonIter m_CandiBone; 187 188 /** the candidate list */ 189 CCandidates m_CandiList; 190 191 /** the index in whole list of first candidate shown in the candidate bar */ 192 int m_CandiFirst; 193 194 /** tail sentence starting from m_CandiFirst */ 195 wstring m_TailSentence; 196 197 private: 198 void 199 getCandidates(); 200 201 bool 202 cursorAtTail(); 203 }; 204 205 #endif 206