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 SUNPY_IMI_SESSION_VIEW_H
40 #define SUNPY_IMI_SESSION_VIEW_H
42 #include "portability.h"
44 #include "imi_context.h"
45 #include "imi_winHandler.h"
46 #include "imi_uiobjects.h"
51 class CHotkeyProfile : private CNonCopyable
58 m_pageDownKeys.clear();
59 m_modeSwitchKeys.clear();
62 void addPageUpKey(const CKeyEvent& key){
63 m_pageUpKeys.insert(key);
66 void removePageUpKey(const CKeyEvent& key){
67 m_pageUpKeys.erase(key);
70 bool isPageUpKey(const CKeyEvent& key) const {
71 return(m_pageUpKeys.find(key) != m_pageUpKeys.end());
74 void addPageDownKey(const CKeyEvent& key){
75 m_pageDownKeys.insert(key);
78 void removePageDownKey(const CKeyEvent& key){
79 m_pageDownKeys.erase(key);
82 bool isPageDownKey(const CKeyEvent& key) const {
83 return(m_pageDownKeys.find(key) != m_pageDownKeys.end());
86 void addModeSwitchKey(const CKeyEvent& key){
87 m_modeSwitchKeys.insert(key);
90 void removeModeSwitchKey(const CKeyEvent& key){
91 m_modeSwitchKeys.erase(key);
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();
98 if (matches(*it, key))
104 void setPunctSwitchKey(const CKeyEvent& key){
105 m_punctSwitchKey = key;
108 bool isPunctSwitchKey(const CKeyEvent& key) const {
109 return matches(m_punctSwitchKey, key);
112 void setSymbolSwitchKey(const CKeyEvent& key){
113 m_symbolSwitchKey = key;
116 bool isSymbolSwitchKey(const CKeyEvent& key) const {
117 return matches(m_symbolSwitchKey, key);
120 void rememberLastKey(const CKeyEvent& key){
124 void setCandiDeleteKey(const CKeyEvent& key){
125 m_candiDeleteKey = key;
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));
135 bool matches(const CKeyEvent& lhs, const CKeyEvent& rhs) const {
137 return(!(lhs.modifiers & IM_RELEASE_MASK) ||
138 m_prevKey.code == rhs.code);
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;
156 PREEDIT_MASK = (1 << 2),
157 CANDIDATE_MASK = (1 << 3)
162 virtual ~CIMIView() {}
164 void attachIC(CIMIContext* pIC) { m_pIC = pIC; }
165 CIMIContext* getIC(void) const { return m_pIC; }
167 void setPySegmentor(IPySegmentor *p) { m_pPySegmentor = p; }
168 IPySegmentor* getPySegmentor() const { return m_pPySegmentor; }
170 void attachWinHandler(CIMIWinHandler* wh) { m_pWinHandler = wh; }
171 CIMIWinHandler* getWinHandler(void) const { return m_pWinHandler; }
173 void setHotkeyProfile(CHotkeyProfile *prof) { m_pHotkeyProfile = prof; }
174 void setCandiWindowSize(unsigned size) {
175 m_candiWindowSize = size;
178 CHotkeyProfile* getHotkeyProfile() { return m_pHotkeyProfile; }
179 unsigned getCandiWindowSize() const { return m_candiWindowSize; }
181 void setCancelOnBackspace(bool backspaceCancel)
182 { m_backspaceCancel = backspaceCancel; }
183 bool getCancelOnBackspace() const { return m_backspaceCancel; }
185 void setSmartPunct(bool smart) { m_smartPunct = smart; }
186 bool getSmartPunct() const { return m_smartPunct; }
188 virtual unsigned clearIC(void) { m_pIC->clear(); return 0; }
189 virtual bool onKeyEvent(const CKeyEvent&) { return false; }
191 virtual void setStatusAttrValue(int key, int value);
192 virtual int getStatusAttrValue(int key);
193 virtual void updateWindows(unsigned mask = CANDIDATE_MASK) = 0;
195 virtual void getPreeditString(IPreeditString& ps) = 0;
196 virtual void getCandidateList(ICandidateList& cl, int start, int size) = 0;
198 virtual int onCandidatePageRequest(int pgno, bool relative) = 0; //pgno == -1, relative == false means last page
199 virtual int onCandidateSelectRequest(int index) = 0;
201 virtual void handlerUpdatePreedit(const IPreeditString* ppd);
202 virtual void handlerUpdateCandidates(IPreeditString* ppd,
203 ICandidateList* pcl);
204 virtual void handlerCommit(const wstring& wstr);
206 #ifdef ENABLE_PLUGINS
208 void _pluginProvideCandidates(wstring preedit, ICandidateList* pcl);
209 void _pluginTranslateCandidate(ICandidateList* pcl);
210 #endif // ENABLE_PLUGINS
214 CIMIWinHandler *m_pWinHandler;
215 IPySegmentor *m_pPySegmentor;
216 CHotkeyProfile *m_pHotkeyProfile;
218 unsigned m_candiWindowSize;
223 bool m_backspaceCancel;