3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER.
5 * Copyright (c) 2007 Sun Microsystems, Inc. All Rights Reserved.
7 * The contents of this file are subject to the terms of either the GNU Lesser
8 * General Public License Version 2.1 only ("LGPL") or the Common Development and
9 * Distribution License ("CDDL")(collectively, the "License"). You may not use this
10 * file except in compliance with the License. You can obtain a copy of the CDDL at
11 * http://www.opensource.org/licenses/cddl1.php and a copy of the LGPLv2.1 at
12 * http://www.opensource.org/licenses/lgpl-license.php. See the License for the
13 * specific language governing permissions and limitations under the License. When
14 * distributing the software, include this License Header Notice in each file and
15 * include the full text of the License in the License file as well as the
18 * NOTICE PURSUANT TO SECTION 9 OF THE COMMON DEVELOPMENT AND DISTRIBUTION LICENSE
20 * For Covered Software in this distribution, this License shall be governed by the
21 * laws of the State of California (excluding conflict-of-law provisions).
22 * Any litigation relating to this License shall be subject to the jurisdiction of
23 * the Federal Courts of the Northern District of California and the state courts
24 * of the State of California, with venue lying in Santa Clara County, California.
28 * If you wish your version of this file to be governed by only the CDDL or only
29 * the LGPL Version 2.1, indicate your decision by adding "[Contributor]" elects to
30 * include this software in this distribution under the [CDDL or LGPL Version 2.1]
31 * license." If you don't indicate a single choice of license, a recipient has the
32 * option to distribute your version of this file under either the CDDL or the LGPL
33 * Version 2.1, or to extend the choice of license to its licensees as provided
34 * above. However, if you add LGPL Version 2.1 code and therefore, elected the LGPL
35 * Version 2 license, then the option applies only if the new code is made subject
36 * to such option by the copyright holder.
39 #ifndef SUNPINYIN_UI_OBJECTS_H
40 #define SUNPINYIN_UI_OBJECTS_H
42 #include "portability.h"
48 #include "imi_context.h"
56 PINYIN_CHAR = 2 + NORMAL_CHAR,
57 ASCII_CHAR = ((PINYIN_CHAR - NORMAL_CHAR) << 1) + NORMAL_CHAR,
58 SYMBOL_CHAR = ((ASCII_CHAR - NORMAL_CHAR) << 1) + NORMAL_CHAR,
59 PUNC_CHAR = ((SYMBOL_CHAR - NORMAL_CHAR) << 1) + NORMAL_CHAR,
60 HANZI_CHAR = ((PUNC_CHAR - NORMAL_CHAR) << 1) + NORMAL_CHAR,
65 USER_CHOICE = (CONVERTED << 1),
66 ILLEGAL = (USER_CHOICE << 1),
67 SELECTION = (ILLEGAL << 1)
71 /** The interface for retrieve Preedit data*/
72 class IPreeditString : public virtual IECharType {
74 typedef std::vector<int> CCharTypeVec;
77 virtual ~IPreeditString() = 0;
80 /** Following functions are used for CIMIWinHandler to retrieve Preedit data. */
81 virtual int size() const = 0;
82 virtual const TWCHAR* string() const = 0;
83 virtual int charTypeSize() const = 0;
84 virtual int charTypeAt(int idx) const = 0;
85 virtual int caret() const = 0;
86 virtual int candi_start() const = 0;
92 * Following functions are used for CIMIView to set Preedit data, should not
93 * be used by CIMIWinHandler.
95 virtual void clear() = 0;
96 virtual wstring& getString() = 0;
97 virtual CCharTypeVec& getCharTypeVec() = 0;
98 virtual void setCaret(int caret) = 0;
99 virtual void setCandiStart(int s) = 0;
103 class CPreEditString : virtual public IPreeditString {
107 virtual ~CPreEditString();
110 virtual int size() const;
111 virtual const TWCHAR* string() const;
112 virtual int charTypeSize() const;
113 virtual int charTypeAt(int idx) const;
114 virtual int caret() const;
115 virtual int candi_start() const;
119 virtual void clear();
120 virtual wstring& getString();
121 virtual CCharTypeVec& getCharTypeVec();
122 virtual void setCaret(int caret);
123 virtual void setCandiStart(int s);
130 CCharTypeVec m_charTypes;
134 /** The interface for retrieve Preedit candidate data*/
135 class ICandidateList : public virtual IECharType {
137 enum ECandidateType {
147 typedef IPreeditString::CCharTypeVec CCharTypeVec;
148 typedef std::vector< CCharTypeVec > CCharTypeVecs;
149 typedef std::vector< wstring > CCandiStrings;
150 typedef std::vector<int> CCandiTypeVec;
153 virtual ~ICandidateList() = 0;
156 /** Following functions are used for CIMIWinHandler to retrieve Candidate data. */
157 virtual int size() const = 0;
158 virtual int total() const = 0;
159 virtual int first() const = 0;
161 virtual int candiType(unsigned int item) const = 0;
162 virtual int candiSize(unsigned int item) const = 0;
163 virtual const TWCHAR* candiString(unsigned int item) const = 0;
165 virtual int candiCharTypeSizeAt(unsigned int item) const =
167 virtual int candiCharTypeAt(unsigned int item,
168 unsigned int idx) const = 0;
174 * Following functions are used for CIMIView to set Candidate List data, should not
175 * be used by CIMIWinHandler.
177 virtual void clear() = 0;
178 virtual void setTotal(int total) = 0;
179 virtual void setFirst(int first) = 0;
180 virtual void setSize(int count) = 0;
182 virtual void shrinkList() = 0;
183 virtual void pushBackCandidate(wstring wstr, int type,
184 int userIdx = -1) = 0;
185 virtual void insertCandidate(wstring wstr, int type, int rank,
186 int userIdx = -1) = 0;
187 virtual void insertCandidateNoDedup(wstring wstr, int type, int rank,
188 int userIdx = -1) = 0;
190 virtual CCandiStrings & getCandiStrings() = 0;
191 virtual CCandiTypeVec & getCandiTypeVec() = 0;
192 virtual CCharTypeVecs & getCharTypeVecs() = 0;
196 class CCandidateList : virtual public ICandidateList {
200 virtual ~CCandidateList();
203 virtual int size() const;
204 virtual int total() const;
205 virtual int first() const;
207 virtual int candiType(unsigned int item) const;
208 virtual int candiSize(unsigned int item) const;
209 virtual const TWCHAR* candiString(unsigned int item) const;
211 virtual int candiCharTypeSizeAt(unsigned int item) const;
212 virtual int candiCharTypeAt(unsigned int item,
213 unsigned int idx) const;
217 virtual void clear();
218 virtual void setTotal(int total);
219 virtual void setFirst(int first);
220 virtual void setSize(int size);
222 virtual void shrinkList();
223 virtual void pushBackCandidate(wstring wstr, int type, int userIdx = -1);
224 virtual void insertCandidate(wstring wstr, int type, int rank,
226 virtual void insertCandidateNoDedup(wstring wstr, int type, int rank,
229 virtual CCandiStrings & getCandiStrings();
230 virtual CCandiTypeVec & getCandiTypeVec();
231 virtual CCharTypeVecs & getCharTypeVecs();
234 int getUserIndex(int idx) { return m_candiUserIndex[idx]; }
240 CCandiStrings m_candiStrings;
241 CCandiTypeVec m_candiTypes;
242 std::vector<int> m_candiUserIndex;
243 CCharTypeVecs m_candiCharTypeVecs;
245 std::map<wstring, int> m_candiStringsIndex;