Update package version to 1.0.8
[platform/core/uifw/ise-engine-sunpinyin.git] / src / ime-core / imi_view.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 SUNPY_IMI_SESSION_VIEW_H
40 #define SUNPY_IMI_SESSION_VIEW_H
41
42 #include "portability.h"
43
44 #include "imi_context.h"
45 #include "imi_winHandler.h"
46 #include "imi_uiobjects.h"
47 #include "imi_keys.h"
48 #include "utils.h"
49 #include <set>
50
51 class CHotkeyProfile : private CNonCopyable
52 {
53 public:
54     CHotkeyProfile();
55
56     void clear(){
57         m_pageUpKeys.clear();
58         m_pageDownKeys.clear();
59         m_modeSwitchKeys.clear();
60     }
61
62     void addPageUpKey(const CKeyEvent& key){
63         m_pageUpKeys.insert(key);
64     }
65
66     void removePageUpKey(const CKeyEvent& key){
67         m_pageUpKeys.erase(key);
68     }
69
70     bool isPageUpKey(const CKeyEvent& key) const {
71         return(m_pageUpKeys.find(key) != m_pageUpKeys.end());
72     }
73
74     void addPageDownKey(const CKeyEvent& key){
75         m_pageDownKeys.insert(key);
76     }
77
78     void removePageDownKey(const CKeyEvent& key){
79         m_pageDownKeys.erase(key);
80     }
81
82     bool isPageDownKey(const CKeyEvent& key) const {
83         return(m_pageDownKeys.find(key) != m_pageDownKeys.end());
84     }
85
86     void addModeSwitchKey(const CKeyEvent& key){
87         m_modeSwitchKeys.insert(key);
88     }
89
90     void removeModeSwitchKey(const CKeyEvent& key){
91         m_modeSwitchKeys.erase(key);
92     }
93
94     bool isModeSwitchKey(const CKeyEvent& key) const {
95         std::set<CKeyEvent>::const_iterator end(m_modeSwitchKeys.end());
96         for (std::set<CKeyEvent>::const_iterator it = m_modeSwitchKeys.begin();
97              it != end; ++it) {
98             if (matches(*it, key))
99                 return true;
100         }
101         return false;
102     }
103
104     void setPunctSwitchKey(const CKeyEvent& key){
105         m_punctSwitchKey = key;
106     }
107
108     bool isPunctSwitchKey(const CKeyEvent& key) const {
109         return matches(m_punctSwitchKey, key);
110     }
111
112     void setSymbolSwitchKey(const CKeyEvent& key){
113         m_symbolSwitchKey = key;
114     }
115
116     bool isSymbolSwitchKey(const CKeyEvent& key) const {
117         return matches(m_symbolSwitchKey, key);
118     }
119
120     void rememberLastKey(const CKeyEvent& key){
121         m_prevKey = key;
122     }
123
124     void setCandiDeleteKey(const CKeyEvent& key){
125         m_candiDeleteKey = key;
126     }
127
128     bool isCandiDeleteKey(const CKeyEvent& key, unsigned candiWndSize){
129         return (key.modifiers == m_candiDeleteKey.modifiers) &&
130                (key.value >= '0' && key.value <= '9') &&
131                (candiWndSize >= 10 || key.value < ('1' + candiWndSize));
132     }
133
134 private:
135     bool matches(const CKeyEvent& lhs, const CKeyEvent& rhs) const {
136         if (lhs == rhs)
137             return(!(lhs.modifiers & IM_RELEASE_MASK) ||
138                    m_prevKey.code == rhs.code);
139         return false;
140     }
141
142 protected:
143     std::set<CKeyEvent> m_pageUpKeys;
144     std::set<CKeyEvent> m_pageDownKeys;
145     std::set<CKeyEvent> m_modeSwitchKeys;
146     CKeyEvent m_punctSwitchKey;
147     CKeyEvent m_symbolSwitchKey;
148     CKeyEvent m_candiDeleteKey;
149     CKeyEvent m_prevKey;
150 };
151
152 class CIMIView {
153 public:
154     enum {
155         KEYEVENT_USED  = (1),
156         PREEDIT_MASK   = (1 << 2),
157         CANDIDATE_MASK = (1 << 3)
158     };
159
160 public:
161     CIMIView();
162     virtual ~CIMIView() {}
163
164     void attachIC(CIMIContext* pIC) { m_pIC = pIC; }
165     CIMIContext* getIC(void) const { return m_pIC; }
166
167     void setPySegmentor(IPySegmentor *p) { m_pPySegmentor = p; }
168     IPySegmentor* getPySegmentor() const { return m_pPySegmentor; }
169
170     void attachWinHandler(CIMIWinHandler* wh) { m_pWinHandler = wh; }
171     CIMIWinHandler* getWinHandler(void) const { return m_pWinHandler; }
172
173     void setHotkeyProfile(CHotkeyProfile *prof) { m_pHotkeyProfile = prof; }
174     void setCandiWindowSize(unsigned size) {
175         m_candiWindowSize = size;
176     }
177
178     CHotkeyProfile* getHotkeyProfile() { return m_pHotkeyProfile; }
179     unsigned getCandiWindowSize() const { return m_candiWindowSize; }
180
181     void setCancelOnBackspace(bool backspaceCancel)
182     { m_backspaceCancel = backspaceCancel; }
183     bool getCancelOnBackspace() const { return m_backspaceCancel; }
184
185     void setSmartPunct(bool smart) { m_smartPunct = smart; }
186     bool getSmartPunct() const { return m_smartPunct; }
187
188     virtual unsigned clearIC(void) { m_pIC->clear(); return 0; }
189     virtual bool onKeyEvent(const CKeyEvent&) { return false; }
190
191     virtual void setStatusAttrValue(int key, int value);
192     virtual int  getStatusAttrValue(int key);
193     virtual void updateWindows(unsigned mask = CANDIDATE_MASK) = 0;
194
195     virtual void getPreeditString(IPreeditString& ps) = 0;
196     virtual void getCandidateList(ICandidateList& cl, int start, int size) = 0;
197
198     virtual int  onCandidatePageRequest(int pgno, bool relative) = 0; //pgno == -1, relative == false means last page
199     virtual int  onCandidateSelectRequest(int index) = 0;
200
201     virtual void handlerUpdatePreedit(const IPreeditString* ppd);
202     virtual void handlerUpdateCandidates(IPreeditString* ppd,
203                                          ICandidateList* pcl);
204     virtual void handlerCommit(const wstring& wstr);
205
206 #ifdef ENABLE_PLUGINS
207 private:
208     void _pluginProvideCandidates(wstring preedit, ICandidateList* pcl);
209     void _pluginTranslateCandidate(ICandidateList* pcl);
210 #endif // ENABLE_PLUGINS
211
212 protected:
213     CIMIContext        *m_pIC;
214     CIMIWinHandler     *m_pWinHandler;
215     IPySegmentor       *m_pPySegmentor;
216     CHotkeyProfile     *m_pHotkeyProfile;
217
218     unsigned m_candiWindowSize;
219
220     bool m_bCN;
221     bool m_bFullPunct;
222     bool m_bFullSymbol;
223     bool m_backspaceCancel;
224     bool m_smartPunct;
225 };
226
227 #endif