~ubuntu-branches/ubuntu/raring/sunpinyin/raring

« back to all changes in this revision

Viewing changes to src/ime-core/imi_view.h

  • Committer: Package Import Robot
  • Author(s): YunQiang Su
  • Date: 2012-03-30 15:31:55 UTC
  • mfrom: (1.1.3) (1.2.7 sid)
  • Revision ID: package-import@ubuntu.com-20120330153155-qgls77sogzgtg9zp
Tags: 2.0.3+git20120222-1
* Team upload: git snapshot 20120222.
   - fix breaks if LDFLAGS in environment contains
       multiple words (Closese #646001).
   - rm patches merged to upstream:
       append-os-environ-toenv.patch
       fix-ftbfs-on-sh.patch
       remove-10-candidate-words-limitation.patch
   - refresh disable-lm-dict-compile.patch.
* Bump stardard version to 3.9.3: no modify needed.
* add libsunpinyin3-dbg and python-sunpinyin packages.
* debian/compat to 9, multiarch it.
* rewrite debian/rules with dh 7 format.

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
1
/*
2
2
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER.
3
 
 * 
 
3
 *
4
4
 * Copyright (c) 2007 Sun Microsystems, Inc. All Rights Reserved.
5
 
 * 
 
5
 *
6
6
 * The contents of this file are subject to the terms of either the GNU Lesser
7
7
 * General Public License Version 2.1 only ("LGPL") or the Common Development and
8
8
 * Distribution License ("CDDL")(collectively, the "License"). You may not use this
9
9
 * file except in compliance with the License. You can obtain a copy of the CDDL at
10
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 
 
11
 * http://www.opensource.org/licenses/lgpl-license.php. See the License for the
12
12
 * specific language governing permissions and limitations under the License. When
13
13
 * distributing the software, include this License Header Notice in each file and
14
14
 * include the full text of the License in the License file as well as the
15
15
 * following notice:
16
 
 * 
 
16
 *
17
17
 * NOTICE PURSUANT TO SECTION 9 OF THE COMMON DEVELOPMENT AND DISTRIBUTION LICENSE
18
18
 * (CDDL)
19
19
 * For Covered Software in this distribution, this License shall be governed by the
21
21
 * Any litigation relating to this License shall be subject to the jurisdiction of
22
22
 * the Federal Courts of the Northern District of California and the state courts
23
23
 * of the State of California, with venue lying in Santa Clara County, California.
24
 
 * 
 
24
 *
25
25
 * Contributor(s):
26
 
 * 
 
26
 *
27
27
 * If you wish your version of this file to be governed by only the CDDL or only
28
28
 * the LGPL Version 2.1, indicate your decision by adding "[Contributor]" elects to
29
29
 * include this software in this distribution under the [CDDL or LGPL Version 2.1]
32
32
 * Version 2.1, or to extend the choice of license to its licensees as provided
33
33
 * above. However, if you add LGPL Version 2.1 code and therefore, elected the LGPL
34
34
 * Version 2 license, then the option applies only if the new code is made subject
35
 
 * to such option by the copyright holder. 
 
35
 * to such option by the copyright holder.
36
36
 */
37
37
 
38
38
#ifndef SUNPY_IMI_SESSION_VIEW_H
51
51
{
52
52
public:
53
53
    CHotkeyProfile();
54
 
    
55
 
    void clear () 
56
 
    {
 
54
 
 
55
    void clear(){
57
56
        m_pageUpKeys.clear();
58
57
        m_pageDownKeys.clear();
59
58
        m_modeSwitchKeys.clear();
60
59
    }
61
60
 
62
 
    void addPageUpKey (const CKeyEvent& key)
63
 
    {
64
 
        m_pageUpKeys.insert (key);
65
 
    }
66
 
 
67
 
    void removePageUpKey (const CKeyEvent& key)
68
 
    {
69
 
        m_pageUpKeys.erase (key);
70
 
    }
71
 
    
72
 
    bool isPageUpKey  (const CKeyEvent& key) const
73
 
    {
74
 
        return (m_pageUpKeys.find (key) != m_pageUpKeys.end());
75
 
    }
76
 
 
77
 
    void addPageDownKey (const CKeyEvent& key)
78
 
    {
79
 
        m_pageDownKeys.insert (key);
80
 
    }
81
 
 
82
 
    void removePageDownKey (const CKeyEvent& key)
83
 
    {
84
 
        m_pageDownKeys.erase (key);
85
 
    }
86
 
    
87
 
    bool isPageDownKey  (const CKeyEvent& key) const
88
 
    {
89
 
        return (m_pageDownKeys.find (key) != m_pageDownKeys.end());
90
 
    }
91
 
 
92
 
    void addModeSwitchKey (const CKeyEvent& key)
93
 
    {
94
 
        m_modeSwitchKeys.insert (key);
95
 
    }
96
 
 
97
 
    void removeModeSwitchKey (const CKeyEvent& key)
98
 
    {
99
 
        m_modeSwitchKeys.erase (key);
100
 
    }
101
 
    
102
 
    bool isModeSwitchKey (const CKeyEvent& key) const
103
 
    {
 
61
    void addPageUpKey(const CKeyEvent& key){
 
62
        m_pageUpKeys.insert(key);
 
63
    }
 
64
 
 
65
    void removePageUpKey(const CKeyEvent& key){
 
66
        m_pageUpKeys.erase(key);
 
67
    }
 
68
 
 
69
    bool isPageUpKey(const CKeyEvent& key) const {
 
70
        return(m_pageUpKeys.find(key) != m_pageUpKeys.end());
 
71
    }
 
72
 
 
73
    void addPageDownKey(const CKeyEvent& key){
 
74
        m_pageDownKeys.insert(key);
 
75
    }
 
76
 
 
77
    void removePageDownKey(const CKeyEvent& key){
 
78
        m_pageDownKeys.erase(key);
 
79
    }
 
80
 
 
81
    bool isPageDownKey(const CKeyEvent& key) const {
 
82
        return(m_pageDownKeys.find(key) != m_pageDownKeys.end());
 
83
    }
 
84
 
 
85
    void addModeSwitchKey(const CKeyEvent& key){
 
86
        m_modeSwitchKeys.insert(key);
 
87
    }
 
88
 
 
89
    void removeModeSwitchKey(const CKeyEvent& key){
 
90
        m_modeSwitchKeys.erase(key);
 
91
    }
 
92
 
 
93
    bool isModeSwitchKey(const CKeyEvent& key) const {
104
94
        std::set<CKeyEvent>::const_iterator end(m_modeSwitchKeys.end());
105
95
        for (std::set<CKeyEvent>::const_iterator it = m_modeSwitchKeys.begin();
106
96
             it != end; ++it) {
109
99
        }
110
100
        return false;
111
101
    }
112
 
    
113
 
    void setPunctSwitchKey (const CKeyEvent& key)
114
 
    {
 
102
 
 
103
    void setPunctSwitchKey(const CKeyEvent& key){
115
104
        m_punctSwitchKey = key;
116
105
    }
117
 
    
118
 
    bool isPunctSwitchKey (const CKeyEvent& key) const
119
 
    {
 
106
 
 
107
    bool isPunctSwitchKey(const CKeyEvent& key) const {
120
108
        return matches(m_punctSwitchKey, key);
121
109
    }
122
 
    
123
 
    void setSymbolSwitchKey (const CKeyEvent& key)
124
 
    {
 
110
 
 
111
    void setSymbolSwitchKey(const CKeyEvent& key){
125
112
        m_symbolSwitchKey = key;
126
113
    }
127
 
    
128
 
    bool isSymbolSwitchKey (const CKeyEvent& key) const
129
 
    {
 
114
 
 
115
    bool isSymbolSwitchKey(const CKeyEvent& key) const {
130
116
        return matches(m_symbolSwitchKey, key);
131
117
    }
132
118
 
133
 
    void rememberLastKey(const CKeyEvent& key)
134
 
    {
 
119
    void rememberLastKey(const CKeyEvent& key){
135
120
        m_prevKey = key;
136
121
    }
137
122
 
138
 
    void setCandiDeleteKey (const CKeyEvent& key)
139
 
    {
 
123
    void setCandiDeleteKey(const CKeyEvent& key){
140
124
        m_candiDeleteKey = key;
141
125
    }
142
126
 
143
 
    bool isCandiDeleteKey (const CKeyEvent& key, unsigned candiWndSize)
144
 
    {
 
127
    bool isCandiDeleteKey(const CKeyEvent& key, unsigned candiWndSize){
145
128
        return (key.modifiers == m_candiDeleteKey.modifiers) &&
146
 
               (key.value >= '0' && key.value <= '9') && 
 
129
               (key.value >= '0' && key.value <= '9') &&
147
130
               (candiWndSize >= 10 || key.value < ('1' + candiWndSize));
148
131
    }
149
 
    
 
132
 
150
133
private:
151
 
    bool matches(const CKeyEvent& lhs, const CKeyEvent& rhs) const
152
 
    {
 
134
    bool matches(const CKeyEvent& lhs, const CKeyEvent& rhs) const {
153
135
        if (lhs == rhs)
154
 
            return ( !(lhs.modifiers & IM_RELEASE_MASK) ||
155
 
                     m_prevKey.code == rhs.code );
 
136
            return(!(lhs.modifiers & IM_RELEASE_MASK) ||
 
137
                   m_prevKey.code == rhs.code);
156
138
        return false;
157
139
    }
158
 
    
 
140
 
159
141
protected:
160
142
    std::set<CKeyEvent> m_pageUpKeys;
161
143
    std::set<CKeyEvent> m_pageDownKeys;
162
144
    std::set<CKeyEvent> m_modeSwitchKeys;
163
 
    CKeyEvent           m_punctSwitchKey;
164
 
    CKeyEvent           m_symbolSwitchKey;
165
 
    CKeyEvent           m_candiDeleteKey;
166
 
    CKeyEvent           m_prevKey;
 
145
    CKeyEvent m_punctSwitchKey;
 
146
    CKeyEvent m_symbolSwitchKey;
 
147
    CKeyEvent m_candiDeleteKey;
 
148
    CKeyEvent m_prevKey;
167
149
};
168
150
 
169
151
class CIMIView {
170
152
public:
171
153
    enum {
172
154
        KEYEVENT_USED  = (1),
173
 
        PREEDIT_MASK   = (1<<2),
174
 
        CANDIDATE_MASK = (1<<3)
 
155
        PREEDIT_MASK   = (1 << 2),
 
156
        CANDIDATE_MASK = (1 << 3)
175
157
    };
176
158
 
177
159
public:
178
160
    CIMIView();
179
161
    virtual ~CIMIView() {}
180
162
 
181
 
    void attachIC(CIMIContext* pIC) {m_pIC = pIC;}
182
 
    CIMIContext* getIC(void) {return m_pIC;}
183
 
 
184
 
    void setPySegmentor (IPySegmentor *p) {m_pPySegmentor = p;}
185
 
    IPySegmentor* getPySegmentor () {return m_pPySegmentor;}
186
 
 
187
 
    void attachWinHandler(CIMIWinHandler* wh) {m_pWinHandler = wh;}
188
 
    CIMIWinHandler* getWinHandler(void) {return m_pWinHandler;}
189
 
 
190
 
    void setHotkeyProfile (CHotkeyProfile *prof) { m_pHotkeyProfile = prof;}
191
 
    void setCandiWindowSize (unsigned size) {m_candiWindowSize = size;}
 
163
    void attachIC(CIMIContext* pIC) { m_pIC = pIC; }
 
164
    CIMIContext* getIC(void) const { return m_pIC; }
 
165
 
 
166
    void setPySegmentor(IPySegmentor *p) { m_pPySegmentor = p; }
 
167
    IPySegmentor* getPySegmentor() const { return m_pPySegmentor; }
 
168
 
 
169
    void attachWinHandler(CIMIWinHandler* wh) { m_pWinHandler = wh; }
 
170
    CIMIWinHandler* getWinHandler(void) const { return m_pWinHandler; }
 
171
 
 
172
    void setHotkeyProfile(CHotkeyProfile *prof) { m_pHotkeyProfile = prof; }
 
173
    void setCandiWindowSize(unsigned size) {
 
174
        m_candiWindowSize = size;
 
175
    }
 
176
 
192
177
    CHotkeyProfile* getHotkeyProfile() { return m_pHotkeyProfile; }
193
 
    unsigned getCandiWindowSize() { return m_candiWindowSize; }
 
178
    unsigned getCandiWindowSize() const { return m_candiWindowSize; }
194
179
 
195
180
    void setCancelOnBackspace(bool backspaceCancel)
196
181
    { m_backspaceCancel = backspaceCancel; }
197
 
    bool getCancelOnBackspace() { return m_backspaceCancel; }
198
 
 
199
 
    virtual unsigned clearIC(void) {m_pIC->clear(); return 0;}
200
 
    virtual bool onKeyEvent(const CKeyEvent&) {return false;}
 
182
    bool getCancelOnBackspace() const { return m_backspaceCancel; }
 
183
 
 
184
    void setSmartPunct(bool smart) { m_smartPunct = smart; }
 
185
    bool getSmartPunct() const { return m_smartPunct; }
 
186
 
 
187
    virtual unsigned clearIC(void) { m_pIC->clear(); return 0; }
 
188
    virtual bool onKeyEvent(const CKeyEvent&) { return false; }
201
189
 
202
190
    virtual void setStatusAttrValue(int key, int value);
203
191
    virtual int  getStatusAttrValue(int key);
204
 
    virtual void updateWindows(unsigned mask) = 0;
 
192
    virtual void updateWindows(unsigned mask = CANDIDATE_MASK) = 0;
205
193
 
206
194
    virtual void getPreeditString(IPreeditString& ps) = 0;
207
195
    virtual void getCandidateList(ICandidateList& cl, int start, int size) = 0;
209
197
    virtual int  onCandidatePageRequest(int pgno, bool relative) = 0; //pgno == -1, relative == false means last page
210
198
    virtual int  onCandidateSelectRequest(int index) = 0;
211
199
 
 
200
    virtual void handlerUpdatePreedit(const IPreeditString* ppd);
 
201
    virtual void handlerUpdateCandidates(IPreeditString* ppd,
 
202
                                         ICandidateList* pcl);
 
203
    virtual void handlerCommit(const wstring& wstr);
 
204
private:
 
205
    void _pluginProvideCandidates(wstring preedit, ICandidateList* pcl);
 
206
    void _pluginTranslateCandidate(ICandidateList* pcl);
212
207
protected:
213
208
    CIMIContext        *m_pIC;
214
209
    CIMIWinHandler     *m_pWinHandler;
215
210
    IPySegmentor       *m_pPySegmentor;
216
211
    CHotkeyProfile     *m_pHotkeyProfile;
217
212
 
218
 
    unsigned            m_candiWindowSize;
 
213
    unsigned m_candiWindowSize;
219
214
 
220
 
    bool                m_bCN;
221
 
    bool                m_bFullPunct;
222
 
    bool                m_bFullSymbol;
223
 
    bool                m_backspaceCancel;
 
215
    bool m_bCN;
 
216
    bool m_bFullPunct;
 
217
    bool m_bFullSymbol;
 
218
    bool m_backspaceCancel;
 
219
    bool m_smartPunct;
224
220
};
225
221
 
226
222
#endif