2
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER.
4
* Copyright (c) 2010 Yong Sun <mail@yongsun.me>
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
17
* NOTICE PURSUANT TO SECTION 9 OF THE COMMON DEVELOPMENT AND DISTRIBUTION LICENSE
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.
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.
38
#import "imi_session_wrapper.h"
40
CSunpinyinSessionWrapper::CSunpinyinSessionWrapper(id ic) : m_ic(ic), m_pv(0), m_wh(0), m_hotkey_profile(0)
42
CSunpinyinSessionFactory& factory = CSunpinyinSessionFactory::getFactory();
44
m_pv = factory.createSession();
49
m_hotkey_profile = new CHotkeyProfile();
50
m_pv->setHotkeyProfile (m_hotkey_profile);
52
m_wh = new CIMKitWindowHandler(m_ic);
53
m_pv->attachWinHandler (m_wh);
55
apply_configuration ();
58
CSunpinyinSessionWrapper::~CSunpinyinSessionWrapper()
61
CSunpinyinSessionFactory& factory = CSunpinyinSessionFactory::getFactory();
62
factory.destroySession(m_pv);
65
delete m_hotkey_profile;
69
void CSunpinyinSessionWrapper::switchInputMode (bool isEnglish, ECommitPolicies policy)
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);
83
bool CSunpinyinSessionWrapper::onConfigChanged (const COptionEvent& event)
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);
107
void CSunpinyinSessionWrapper::windowHandlerTimerCallback()
110
m_wh->doneDeferedUpdate();
111
m_pv->updateWindows();
115
void CSunpinyinSessionWrapper::apply_configuration()
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));
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);
126
m_pv->setCancelOnBackspace(CSessionConfigStore::instance().m_cancel_on_backspace);
129
void CSunpinyinSessionWrapper::update_cand_window_size(unsigned size)
131
m_pv->setCandiWindowSize(size);
134
void CSunpinyinSessionWrapper::update_page_key_minus(bool enable)
136
update_page_key(IM_VK_MINUS, IM_VK_EQUALS, enable);
139
void CSunpinyinSessionWrapper::update_page_key_comma(bool enable)
141
update_page_key(IM_VK_COMMA, IM_VK_PERIOD, enable);
144
void CSunpinyinSessionWrapper::update_page_key_bracket(bool enable)
146
update_page_key(IM_VK_OPEN_BRACKET, IM_VK_CLOSE_BRACKET, enable);
149
void CSunpinyinSessionWrapper::update_page_key_arrows(bool enable)
151
update_page_key(IM_VK_UP, IM_VK_DOWN, enable);
154
void CSunpinyinSessionWrapper::update_page_key(unsigned page_up, unsigned page_down, bool enable)
157
m_hotkey_profile->addPageUpKey(CKeyEvent(page_up, page_up));
158
m_hotkey_profile->addPageDownKey(CKeyEvent(page_down, page_down));
160
m_hotkey_profile->removePageUpKey(CKeyEvent(page_up, page_up));
161
m_hotkey_profile->removePageDownKey(CKeyEvent(page_down, page_down));
165
void CSunpinyinSessionWrapper::update_charset_level(unsigned charset)
167
// charset can only be 0,1,2 or 3
168
m_pv->getIC()->setCharsetLevel(charset & 3);