~ubuntu-branches/ubuntu/quantal/sunpinyin/quantal

« back to all changes in this revision

Viewing changes to wrapper/macos/imi_session_wrapper.mm

  • 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
/*
 
2
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER.
 
3
 * 
 
4
 * Copyright (c) 2010 Yong Sun <mail@yongsun.me>
 
5
 * 
 
6
 * The contents of this file are subject to the terms of either the GNU Lesser
 
7
 * General Public License Version 2.1 only ("LGPL") or the Common Development and
 
8
 * Distribution License ("CDDL")(collectively, the "License"). You may not use this
 
9
 * file except in compliance with the License. You can obtain a copy of the CDDL at
 
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 
 
12
 * specific language governing permissions and limitations under the License. When
 
13
 * distributing the software, include this License Header Notice in each file and
 
14
 * include the full text of the License in the License file as well as the
 
15
 * following notice:
 
16
 * 
 
17
 * NOTICE PURSUANT TO SECTION 9 OF THE COMMON DEVELOPMENT AND DISTRIBUTION LICENSE
 
18
 * (CDDL)
 
19
 * For Covered Software in this distribution, this License shall be governed by the
 
20
 * laws of the State of California (excluding conflict-of-law provisions).
 
21
 * Any litigation relating to this License shall be subject to the jurisdiction of
 
22
 * the Federal Courts of the Northern District of California and the state courts
 
23
 * of the State of California, with venue lying in Santa Clara County, California.
 
24
 * 
 
25
 * Contributor(s):
 
26
 * 
 
27
 * If you wish your version of this file to be governed by only the CDDL or only
 
28
 * the LGPL Version 2.1, indicate your decision by adding "[Contributor]" elects to
 
29
 * include this software in this distribution under the [CDDL or LGPL Version 2.1]
 
30
 * license." If you don't indicate a single choice of license, a recipient has the
 
31
 * option to distribute your version of this file under either the CDDL or the LGPL
 
32
 * Version 2.1, or to extend the choice of license to its licensees as provided
 
33
 * above. However, if you add LGPL Version 2.1 code and therefore, elected the LGPL
 
34
 * Version 2 license, then the option applies only if the new code is made subject
 
35
 * to such option by the copyright holder. 
 
36
 */
 
37
 
 
38
#import "imi_session_wrapper.h"
 
39
 
 
40
CSunpinyinSessionWrapper::CSunpinyinSessionWrapper(id ic) : m_ic(ic), m_pv(0), m_wh(0), m_hotkey_profile(0)
 
41
{
 
42
    CSunpinyinSessionFactory& factory = CSunpinyinSessionFactory::getFactory();
 
43
    
 
44
    m_pv = factory.createSession();
 
45
    
 
46
    if (!m_pv)
 
47
        return;
 
48
 
 
49
    m_hotkey_profile = new CHotkeyProfile();
 
50
    m_pv->setHotkeyProfile (m_hotkey_profile);
 
51
 
 
52
    m_wh = new CIMKitWindowHandler(m_ic);
 
53
    m_pv->attachWinHandler (m_wh);
 
54
    
 
55
    apply_configuration ();
 
56
}
 
57
 
 
58
CSunpinyinSessionWrapper::~CSunpinyinSessionWrapper()
 
59
{
 
60
    if (m_pv) {
 
61
        CSunpinyinSessionFactory& factory = CSunpinyinSessionFactory::getFactory();
 
62
        factory.destroySession(m_pv);
 
63
    }
 
64
 
 
65
    delete m_hotkey_profile;
 
66
    delete m_wh;
 
67
}
 
68
 
 
69
void CSunpinyinSessionWrapper::switchInputMode (bool isEnglish, ECommitPolicies policy)
 
70
{
 
71
    if (!isValid())
 
72
        return;
 
73
 
 
74
    if (isEnglish) {
 
75
        // We need two spaces to commit in modern style
 
76
        if (COMMIT_PINYIN_STRING == policy)
 
77
            m_pv->onKeyEvent (CKeyEvent(IM_VK_ENTER, 0, 0));
 
78
        else if (COMMIT_CONVERTED_SENTENCE == policy)
 
79
            m_pv->onCandidateSelectRequest (0);
 
80
    }
 
81
}
 
82
 
 
83
bool CSunpinyinSessionWrapper::onConfigChanged (const COptionEvent& event)
 
84
{
 
85
    if (!isValid())
 
86
        return false;
 
87
 
 
88
    if (event.name == CONFIG_GENERAL_PAGE_SIZE) {
 
89
        update_cand_window_size(event.get_int());
 
90
    } else if (event.name == CONFIG_GENERAL_CHARSET_LEVEL) {
 
91
        update_charset_level(event.get_int());
 
92
    } else if (event.name == CONFIG_KEYBOARD_PAGE_COMMA) {
 
93
        update_page_key_comma(event.get_bool());
 
94
    } else if (event.name == CONFIG_KEYBOARD_PAGE_MINUS) {
 
95
        update_page_key_minus(event.get_bool());
 
96
    } else if (event.name == CONFIG_KEYBOARD_PAGE_BRACKET) {
 
97
        update_page_key_bracket(event.get_bool());
 
98
    } else if (event.name == CONFIG_KEYBOARD_PAGE_ARROWS) {
 
99
        update_page_key_arrows(event.get_bool());
 
100
    } else if (event.name == CONFIG_KEYBOARD_MISC_CANCELONBSP) {
 
101
        m_pv->setCancelOnBackspace(CSessionConfigStore::instance().m_cancel_on_backspace);
 
102
    }
 
103
    
 
104
    return false;
 
105
}
 
106
 
 
107
void CSunpinyinSessionWrapper::windowHandlerTimerCallback()
 
108
{
 
109
    if (isValid()) {
 
110
        m_wh->doneDeferedUpdate();
 
111
        m_pv->updateWindows();
 
112
    }
 
113
}
 
114
 
 
115
void CSunpinyinSessionWrapper::apply_configuration()
 
116
{
 
117
    m_hotkey_profile->setPunctSwitchKey(CKeyEvent(IM_VK_PERIOD, IM_VK_PERIOD, IM_CTRL_MASK));    
 
118
    m_hotkey_profile->setSymbolSwitchKey(CKeyEvent(IM_VK_SPACE, IM_VK_SPACE, IM_ALT_MASK));
 
119
    m_hotkey_profile->setCandiDeleteKey(CKeyEvent(0, 0, IM_CTRL_MASK|IM_SUPER_MASK));
 
120
 
 
121
    update_page_key_minus  (CSessionConfigStore::instance().m_paging_by_minus_equals);
 
122
    update_page_key_comma  (CSessionConfigStore::instance().m_paging_by_comma_period);
 
123
    update_page_key_bracket(CSessionConfigStore::instance().m_paging_by_brackets);
 
124
    update_page_key_arrows (CSessionConfigStore::instance().m_paging_by_arrows);
 
125
    
 
126
    m_pv->setCancelOnBackspace(CSessionConfigStore::instance().m_cancel_on_backspace);
 
127
}
 
128
 
 
129
void CSunpinyinSessionWrapper::update_cand_window_size(unsigned size)
 
130
{
 
131
    m_pv->setCandiWindowSize(size);
 
132
}
 
133
 
 
134
void CSunpinyinSessionWrapper::update_page_key_minus(bool enable)
 
135
{
 
136
    update_page_key(IM_VK_MINUS, IM_VK_EQUALS, enable);
 
137
}
 
138
 
 
139
void CSunpinyinSessionWrapper::update_page_key_comma(bool enable)
 
140
{
 
141
    update_page_key(IM_VK_COMMA, IM_VK_PERIOD, enable);
 
142
}
 
143
 
 
144
void CSunpinyinSessionWrapper::update_page_key_bracket(bool enable)
 
145
{
 
146
    update_page_key(IM_VK_OPEN_BRACKET, IM_VK_CLOSE_BRACKET, enable);
 
147
}
 
148
 
 
149
void CSunpinyinSessionWrapper::update_page_key_arrows(bool enable)
 
150
{
 
151
    update_page_key(IM_VK_UP, IM_VK_DOWN, enable);
 
152
}
 
153
 
 
154
void CSunpinyinSessionWrapper::update_page_key(unsigned page_up, unsigned page_down, bool enable)
 
155
{
 
156
    if (enable) {
 
157
        m_hotkey_profile->addPageUpKey(CKeyEvent(page_up, page_up));
 
158
        m_hotkey_profile->addPageDownKey(CKeyEvent(page_down, page_down));
 
159
    } else {
 
160
        m_hotkey_profile->removePageUpKey(CKeyEvent(page_up, page_up));
 
161
        m_hotkey_profile->removePageDownKey(CKeyEvent(page_down, page_down));
 
162
    }
 
163
}
 
164
 
 
165
void CSunpinyinSessionWrapper::update_charset_level(unsigned charset)
 
166
{
 
167
    // charset can only be 0,1,2 or 3
 
168
    m_pv->getIC()->setCharsetLevel(charset & 3);
 
169
}