Tizen 2.1 base
[platform/core/uifw/ise-engine-sunpinyin.git] / src / ime-core / imi_uiobjects.h
1 // -*- mode: c++ -*-
2 /*
3  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER.
4  *
5  * Copyright (c) 2007 Sun Microsystems, Inc. All Rights Reserved.
6  *
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
16  * following notice:
17  *
18  * NOTICE PURSUANT TO SECTION 9 OF THE COMMON DEVELOPMENT AND DISTRIBUTION LICENSE
19  * (CDDL)
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.
25  *
26  * Contributor(s):
27  *
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.
37  */
38
39 #ifndef SUNPINYIN_UI_OBJECTS_H
40 #define SUNPINYIN_UI_OBJECTS_H
41
42 #include "portability.h"
43
44 #include <vector>
45 #include <string>
46 #include <map>
47
48 #include "imi_context.h"
49
50 class IECharType {
51 public:
52     enum ECharType {
53         DONTCARE_CHAR   = 0,
54
55         NORMAL_CHAR     = 1,
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,
61
62         BOUNDARY        = 256,
63
64         CONVERTED       = 0x10000,
65         USER_CHOICE     = (CONVERTED << 1),
66         ILLEGAL         = (USER_CHOICE << 1),
67         SELECTION       = (ILLEGAL << 1)
68     };
69 };
70
71 /** The interface for retrieve Preedit data*/
72 class IPreeditString : public virtual IECharType {
73 public:
74     typedef std::vector<int>    CCharTypeVec;
75
76 public:
77     virtual ~IPreeditString() = 0;
78
79     /*@{*/
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;
87     /*@}*/
88
89 public:
90     /*@{*/
91     /**
92      * Following functions are used for CIMIView to set Preedit data, should not
93      * be used by CIMIWinHandler.
94      */
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;
100     /*@}*/
101 };
102
103 class CPreEditString : virtual public IPreeditString {
104 public:
105     CPreEditString();
106
107     virtual ~CPreEditString();
108
109     /*@{*/
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;
116     /*@}*/
117
118     /*@{*/
119     virtual void                clear();
120     virtual wstring&            getString();
121     virtual CCharTypeVec&       getCharTypeVec();
122     virtual void                setCaret(int caret);
123     virtual void                setCandiStart(int s);
124     /*@}*/
125
126 protected:
127     wstring m_wstr;
128     int m_caret;
129     int m_candi_start;
130     CCharTypeVec m_charTypes;
131 };
132
133
134 /** The interface for retrieve Preedit candidate data*/
135 class ICandidateList : public virtual IECharType {
136 public:
137     enum ECandidateType {
138         NORMAL_WORD = 0,
139         AS_INPUT,
140         BEST_WORD,
141         USER_SELECTED_WORD,
142         BEST_TAIL,
143         PLUGIN_TAIL,
144         OTHER_BEST_TAIL
145     };
146
147     typedef IPreeditString::CCharTypeVec CCharTypeVec;
148     typedef std::vector< CCharTypeVec >         CCharTypeVecs;
149     typedef std::vector< wstring >              CCandiStrings;
150     typedef std::vector<int>                    CCandiTypeVec;
151
152 public:
153     virtual ~ICandidateList() = 0;
154
155     /*@{*/
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;
160
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;
164
165     virtual int                 candiCharTypeSizeAt(unsigned int item) const =
166         0;
167     virtual int                 candiCharTypeAt(unsigned int item,
168                                                 unsigned int idx) const = 0;
169     /*@}*/
170
171 public:
172     /*@{*/
173     /**
174      * Following functions are used for CIMIView to set Candidate List data, should not
175      * be used by CIMIWinHandler.
176      */
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;
181
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;
189
190     virtual CCandiStrings &     getCandiStrings() = 0;
191     virtual CCandiTypeVec &     getCandiTypeVec() = 0;
192     virtual CCharTypeVecs &     getCharTypeVecs() = 0;
193     /*@}*/
194 };
195
196 class CCandidateList : virtual public ICandidateList {
197 public:
198     CCandidateList();
199
200     virtual ~CCandidateList();
201
202     /*@{*/
203     virtual int                 size() const;
204     virtual int                 total() const;
205     virtual int                 first() const;
206
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;
210
211     virtual int                 candiCharTypeSizeAt(unsigned int item) const;
212     virtual int                 candiCharTypeAt(unsigned int item,
213                                                 unsigned int idx) const;
214     /*@}*/
215
216     /*@{*/
217     virtual void                clear();
218     virtual void                setTotal(int total);
219     virtual void                setFirst(int first);
220     virtual void                setSize(int size);
221
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,
225                                  int userIdx = -1);
226     virtual void insertCandidateNoDedup(wstring wstr, int type, int rank,
227                                         int userIdx = -1);
228
229     virtual CCandiStrings &     getCandiStrings();
230     virtual CCandiTypeVec &     getCandiTypeVec();
231     virtual CCharTypeVecs &     getCharTypeVecs();
232     /*@}*/
233
234     int getUserIndex(int idx) { return m_candiUserIndex[idx]; }
235
236 protected:
237     int m_total;
238     int m_first;
239     int m_size;
240     CCandiStrings m_candiStrings;
241     CCandiTypeVec m_candiTypes;
242     std::vector<int> m_candiUserIndex;
243     CCharTypeVecs m_candiCharTypeVecs;
244
245     std::map<wstring, int> m_candiStringsIndex;
246 };
247
248 #endif