Add support uim-mozc
uim-mozc is a program to use mozc in uim. This is not yet included in mozc.
It is developed in MacUIM project. License is BSD license.
svn checkout http://macuim.googlecode.com/svn/trunk/ r187
Signed-off-by: Nobuhiro Iwamatsu <iwamatsu@debian.org>
Nobuhiro Iwamatsu
13 years ago
0 | From 3c2356b28c283d448bebcb7e92173095cb5736c7 Mon Sep 17 00:00:00 2001 | |
1 | From: Nobuhiro Iwamatsu <iwamatsu@debian.org> | |
2 | Date: Thu, 22 Jul 2010 05:36:30 +0900 | |
3 | Subject: [PATCH] Add uim-mozc r187 | |
4 | ||
5 | svn checkout http://macuim.googlecode.com/svn/trunk/ | |
6 | ||
7 | Signed-off-by: Nobuhiro Iwamatsu <iwamatsu@debian.org> | |
8 | --- | |
9 | unix/uim/key_translator.cc | 435 +++++++++++++++++ | |
10 | unix/uim/key_translator.h | 110 +++++ | |
11 | unix/uim/mozc.cc | 994 ++++++++++++++++++++++++++++++++++++++ | |
12 | unix/uim/scm/mozc-custom.scm | 259 ++++++++++ | |
13 | unix/uim/scm/mozc-key-custom.scm | 74 +++ | |
14 | unix/uim/scm/mozc.scm | 350 ++++++++++++++ | |
15 | unix/uim/uim.gyp | 82 ++++ | |
16 | 7 files changed, 2304 insertions(+), 0 deletions(-) | |
17 | create mode 100644 unix/uim/key_translator.cc | |
18 | create mode 100644 unix/uim/key_translator.h | |
19 | create mode 100644 unix/uim/mozc.cc | |
20 | create mode 100644 unix/uim/scm/mozc-custom.scm | |
21 | create mode 100644 unix/uim/scm/mozc-key-custom.scm | |
22 | create mode 100644 unix/uim/scm/mozc.scm | |
23 | create mode 100644 unix/uim/uim.gyp | |
24 | ||
25 | diff --git a/unix/uim/key_translator.cc b/unix/uim/key_translator.cc | |
26 | new file mode 100644 | |
27 | index 0000000..6342548 | |
28 | --- /dev/null | |
29 | +++ b/unix/uim/key_translator.cc | |
30 | @@ -0,0 +1,435 @@ | |
31 | +// Copyright 2010, Google Inc. | |
32 | +// All rights reserved. | |
33 | +// | |
34 | +// Redistribution and use in source and binary forms, with or without | |
35 | +// modification, are permitted provided that the following conditions are | |
36 | +// met: | |
37 | +// | |
38 | +// * Redistributions of source code must retain the above copyright | |
39 | +// notice, this list of conditions and the following disclaimer. | |
40 | +// * Redistributions in binary form must reproduce the above | |
41 | +// copyright notice, this list of conditions and the following disclaimer | |
42 | +// in the documentation and/or other materials provided with the | |
43 | +// distribution. | |
44 | +// * Neither the name of Google Inc. nor the names of its | |
45 | +// contributors may be used to endorse or promote products derived from | |
46 | +// this software without specific prior written permission. | |
47 | +// | |
48 | +// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS | |
49 | +// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT | |
50 | +// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR | |
51 | +// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT | |
52 | +// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, | |
53 | +// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT | |
54 | +// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, | |
55 | +// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY | |
56 | +// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT | |
57 | +// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE | |
58 | +// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. | |
59 | + | |
60 | +#include "unix/uim/key_translator.h" | |
61 | + | |
62 | +#include <uim.h> | |
63 | + | |
64 | +#include "base/logging.h" | |
65 | + | |
66 | +namespace { | |
67 | + | |
68 | +const struct SpecialKeyMap { | |
69 | + unsigned int from; | |
70 | + mozc::commands::KeyEvent::SpecialKey to; | |
71 | +} special_key_map[] = { | |
72 | + {0x20, mozc::commands::KeyEvent::SPACE}, | |
73 | + {UKey_Return, mozc::commands::KeyEvent::ENTER}, | |
74 | + {UKey_Left, mozc::commands::KeyEvent::LEFT}, | |
75 | + {UKey_Right, mozc::commands::KeyEvent::RIGHT}, | |
76 | + {UKey_Up, mozc::commands::KeyEvent::UP}, | |
77 | + {UKey_Down, mozc::commands::KeyEvent::DOWN}, | |
78 | + {UKey_Escape, mozc::commands::KeyEvent::ESCAPE}, | |
79 | + {UKey_Delete, mozc::commands::KeyEvent::DEL}, | |
80 | + {UKey_Backspace, mozc::commands::KeyEvent::BACKSPACE}, | |
81 | + {UKey_Insert, mozc::commands::KeyEvent::INSERT}, | |
82 | + {UKey_Henkan, mozc::commands::KeyEvent::HENKAN}, | |
83 | + {UKey_Muhenkan, mozc::commands::KeyEvent::MUHENKAN}, | |
84 | + {UKey_Hiragana, mozc::commands::KeyEvent::KANA}, | |
85 | + {UKey_Katakana, mozc::commands::KeyEvent::KANA}, | |
86 | + {UKey_Eisu_toggle, mozc::commands::KeyEvent::EISU}, | |
87 | + {UKey_Home, mozc::commands::KeyEvent::HOME}, | |
88 | + {UKey_End, mozc::commands::KeyEvent::END}, | |
89 | + {UKey_Tab, mozc::commands::KeyEvent::TAB}, | |
90 | + {UKey_F1, mozc::commands::KeyEvent::F1}, | |
91 | + {UKey_F2, mozc::commands::KeyEvent::F2}, | |
92 | + {UKey_F3, mozc::commands::KeyEvent::F3}, | |
93 | + {UKey_F4, mozc::commands::KeyEvent::F4}, | |
94 | + {UKey_F5, mozc::commands::KeyEvent::F5}, | |
95 | + {UKey_F6, mozc::commands::KeyEvent::F6}, | |
96 | + {UKey_F7, mozc::commands::KeyEvent::F7}, | |
97 | + {UKey_F8, mozc::commands::KeyEvent::F8}, | |
98 | + {UKey_F9, mozc::commands::KeyEvent::F9}, | |
99 | + {UKey_F10, mozc::commands::KeyEvent::F10}, | |
100 | + {UKey_F11, mozc::commands::KeyEvent::F11}, | |
101 | + {UKey_F12, mozc::commands::KeyEvent::F12}, | |
102 | + {UKey_F13, mozc::commands::KeyEvent::F13}, | |
103 | + {UKey_F14, mozc::commands::KeyEvent::F14}, | |
104 | + {UKey_F15, mozc::commands::KeyEvent::F15}, | |
105 | + {UKey_F16, mozc::commands::KeyEvent::F16}, | |
106 | + {UKey_F17, mozc::commands::KeyEvent::F17}, | |
107 | + {UKey_F18, mozc::commands::KeyEvent::F18}, | |
108 | + {UKey_F19, mozc::commands::KeyEvent::F19}, | |
109 | + {UKey_F20, mozc::commands::KeyEvent::F20}, | |
110 | + {UKey_F21, mozc::commands::KeyEvent::F21}, | |
111 | + {UKey_F22, mozc::commands::KeyEvent::F22}, | |
112 | + {UKey_F23, mozc::commands::KeyEvent::F23}, | |
113 | + {UKey_F24, mozc::commands::KeyEvent::F24}, | |
114 | + {UKey_Prior, mozc::commands::KeyEvent::PAGE_UP}, | |
115 | + {UKey_Next, mozc::commands::KeyEvent::PAGE_DOWN}, | |
116 | +}; | |
117 | + | |
118 | +const struct ModifierKeyMap { | |
119 | + unsigned int from; | |
120 | + mozc::commands::KeyEvent::ModifierKey to; | |
121 | +} modifier_key_map[] = { | |
122 | + {UKey_Shift, mozc::commands::KeyEvent::SHIFT}, | |
123 | + {UKey_Control, mozc::commands::KeyEvent::CTRL}, | |
124 | + {UKey_Alt, mozc::commands::KeyEvent::ALT}, | |
125 | +}; | |
126 | + | |
127 | +const struct ModifierMaskMap { | |
128 | + unsigned int from; | |
129 | + mozc::commands::KeyEvent::ModifierKey to; | |
130 | +} modifier_mask_map[] = { | |
131 | + {UMod_Shift, mozc::commands::KeyEvent::SHIFT}, | |
132 | + {UMod_Control, mozc::commands::KeyEvent::CTRL}, | |
133 | + {UMod_Alt, mozc::commands::KeyEvent::ALT}, | |
134 | +}; | |
135 | + | |
136 | +// TODO:Add kana_map_dv to support Dvoraklayout. | |
137 | +const struct KanaMap { | |
138 | + unsigned int code; | |
139 | + const char *no_shift; | |
140 | + const char *shift; | |
141 | +} kana_map_jp[] = { | |
142 | + { '1' , "\xe3\x81\xac", "\xe3\x81\xac" }, // "ぬ", "ぬ" | |
143 | + { '!' , "\xe3\x81\xac", "\xe3\x81\xac" }, // "ぬ", "ぬ" | |
144 | + { '2' , "\xe3\x81\xb5", "\xe3\x81\xb5" }, // "ふ", "ふ" | |
145 | + { '\"', "\xe3\x81\xb5", "\xe3\x81\xb5" }, // "ふ", "ふ" | |
146 | + { '3' , "\xe3\x81\x82", "\xe3\x81\x81" }, // "あ", "ぁ" | |
147 | + { '#' , "\xe3\x81\x81", "\xe3\x81\x81" }, // "ぁ", "ぁ" | |
148 | + { '4' , "\xe3\x81\x86", "\xe3\x81\x85" }, // "う", "ぅ" | |
149 | + { '$' , "\xe3\x81\x85", "\xe3\x81\x85" }, // "ぅ", "ぅ" | |
150 | + { '5' , "\xe3\x81\x88", "\xe3\x81\x87" }, // "え", "ぇ" | |
151 | + { '%' , "\xe3\x81\x87", "\xe3\x81\x87" }, // "ぇ", "ぇ" | |
152 | + { '6' , "\xe3\x81\x8a", "\xe3\x81\x89" }, // "お", "ぉ" | |
153 | + { '&' , "\xe3\x81\x89", "\xe3\x81\x89" }, // "ぉ", "ぉ" | |
154 | + { '7' , "\xe3\x82\x84", "\xe3\x82\x83" }, // "や", "ゃ" | |
155 | + { '\'', "\xe3\x82\x83", "\xe3\x82\x83" }, // "ゃ", "ゃ" | |
156 | + { '8' , "\xe3\x82\x86", "\xe3\x82\x85" }, // "ゆ", "ゅ" | |
157 | + { '(' , "\xe3\x82\x85", "\xe3\x82\x85" }, // "ゅ", "ゅ" | |
158 | + { '9' , "\xe3\x82\x88", "\xe3\x82\x87" }, // "よ", "ょ" | |
159 | + { ')' , "\xe3\x82\x87", "\xe3\x82\x87" }, // "ょ", "ょ" | |
160 | + { '0' , "\xe3\x82\x8f", "\xe3\x82\x92" }, // "わ", "を" | |
161 | + { '-' , "\xe3\x81\xbb", "\xe3\x81\xbb" }, // "ほ", "ほ" | |
162 | + { '=' , "\xe3\x81\xbb", "\xe3\x81\xbb" }, // "ほ", "ほ" | |
163 | + { '^' , "\xe3\x81\xb8", "\xe3\x81\xb8" }, // "へ", "へ" | |
164 | + { '~' , "\xe3\x82\x92", "\xe3\x82\x92" }, // "を", "を" | |
165 | + { '|' , "\xe3\x83\xbc", "\xe3\x83\xbc" }, // "ー", "ー" | |
166 | + { 'q' , "\xe3\x81\x9f", "\xe3\x81\x9f" }, // "た", "た" | |
167 | + { 'Q' , "\xe3\x81\x9f", "\xe3\x81\x9f" }, // "た", "た" | |
168 | + { 'w' , "\xe3\x81\xa6", "\xe3\x81\xa6" }, // "て", "て" | |
169 | + { 'W' , "\xe3\x81\xa6", "\xe3\x81\xa6" }, // "て", "て" | |
170 | + { 'e' , "\xe3\x81\x84", "\xe3\x81\x83" }, // "い", "ぃ" | |
171 | + { 'E' , "\xe3\x81\x83", "\xe3\x81\x83" }, // "ぃ", "ぃ" | |
172 | + { 'r' , "\xe3\x81\x99", "\xe3\x81\x99" }, // "す", "す" | |
173 | + { 'R' , "\xe3\x81\x99", "\xe3\x81\x99" }, // "す", "す" | |
174 | + { 't' , "\xe3\x81\x8b", "\xe3\x81\x8b" }, // "か", "か" | |
175 | + { 'T' , "\xe3\x81\x8b", "\xe3\x81\x8b" }, // "か", "か" | |
176 | + { 'y' , "\xe3\x82\x93", "\xe3\x82\x93" }, // "ん", "ん" | |
177 | + { 'Y' , "\xe3\x82\x93", "\xe3\x82\x93" }, // "ん", "ん" | |
178 | + { 'u' , "\xe3\x81\xaa", "\xe3\x81\xaa" }, // "な", "な" | |
179 | + { 'U' , "\xe3\x81\xaa", "\xe3\x81\xaa" }, // "な", "な" | |
180 | + { 'i' , "\xe3\x81\xab", "\xe3\x81\xab" }, // "に", "に" | |
181 | + { 'I' , "\xe3\x81\xab", "\xe3\x81\xab" }, // "に", "に" | |
182 | + { 'o' , "\xe3\x82\x89", "\xe3\x82\x89" }, // "ら", "ら" | |
183 | + { 'O' , "\xe3\x82\x89", "\xe3\x82\x89" }, // "ら", "ら" | |
184 | + { 'p' , "\xe3\x81\x9b", "\xe3\x81\x9b" }, // "せ", "せ" | |
185 | + { 'P' , "\xe3\x81\x9b", "\xe3\x81\x9b" }, // "せ", "せ" | |
186 | + { '@' , "\xe3\x82\x9b", "\xe3\x82\x9b" }, // "゛", "゛" | |
187 | + { '`' , "\xe3\x82\x9b", "\xe3\x82\x9b" }, // "゛", "゛" | |
188 | + { '[' , "\xe3\x82\x9c", "\xe3\x80\x8c" }, // "゜", "「" | |
189 | + { '{' , "\xe3\x82\x9c", "\xe3\x80\x8c" }, // "゜", "「" | |
190 | + { 'a' , "\xe3\x81\xa1", "\xe3\x81\xa1" }, // "ち", "ち" | |
191 | + { 'A' , "\xe3\x81\xa1", "\xe3\x81\xa1" }, // "ち", "ち" | |
192 | + { 's' , "\xe3\x81\xa8", "\xe3\x81\xa8" }, // "と", "と" | |
193 | + { 'S' , "\xe3\x81\xa8", "\xe3\x81\xa8" }, // "と", "と" | |
194 | + { 'd' , "\xe3\x81\x97", "\xe3\x81\x97" }, // "し", "し" | |
195 | + { 'D' , "\xe3\x81\x97", "\xe3\x81\x97" }, // "し", "し" | |
196 | + { 'f' , "\xe3\x81\xaf", "\xe3\x81\xaf" }, // "は", "は" | |
197 | + { 'F' , "\xe3\x81\xaf", "\xe3\x81\xaf" }, // "は", "は" | |
198 | + { 'g' , "\xe3\x81\x8d", "\xe3\x81\x8d" }, // "き", "き" | |
199 | + { 'G' , "\xe3\x81\x8d", "\xe3\x81\x8d" }, // "き", "き" | |
200 | + { 'h' , "\xe3\x81\x8f", "\xe3\x81\x8f" }, // "く", "く" | |
201 | + { 'H' , "\xe3\x81\x8f", "\xe3\x81\x8f" }, // "く", "く" | |
202 | + { 'j' , "\xe3\x81\xbe", "\xe3\x81\xbe" }, // "ま", "ま" | |
203 | + { 'J' , "\xe3\x81\xbe", "\xe3\x81\xbe" }, // "ま", "ま" | |
204 | + { 'k' , "\xe3\x81\xae", "\xe3\x81\xae" }, // "の", "の" | |
205 | + { 'K' , "\xe3\x81\xae", "\xe3\x81\xae" }, // "の", "の" | |
206 | + { 'l' , "\xe3\x82\x8a", "\xe3\x82\x8a" }, // "り", "り" | |
207 | + { 'L' , "\xe3\x82\x8a", "\xe3\x82\x8a" }, // "り", "り" | |
208 | + { ';' , "\xe3\x82\x8c", "\xe3\x82\x8c" }, // "れ", "れ" | |
209 | + { '+' , "\xe3\x82\x8c", "\xe3\x82\x8c" }, // "れ", "れ" | |
210 | + { ':' , "\xe3\x81\x91", "\xe3\x81\x91" }, // "け", "け" | |
211 | + { '*' , "\xe3\x81\x91", "\xe3\x81\x91" }, // "け", "け" | |
212 | + { ']' , "\xe3\x82\x80", "\xe3\x80\x8d" }, // "む", "」" | |
213 | + { '}' , "\xe3\x80\x8d", "\xe3\x80\x8d" }, // "」", "」" | |
214 | + { 'z' , "\xe3\x81\xa4", "\xe3\x81\xa3" }, // "つ", "っ" | |
215 | + { 'Z' , "\xe3\x81\xa3", "\xe3\x81\xa3" }, // "っ", "っ" | |
216 | + { 'x' , "\xe3\x81\x95", "\xe3\x81\x95" }, // "さ", "さ" | |
217 | + { 'X' , "\xe3\x81\x95", "\xe3\x81\x95" }, // "さ", "さ" | |
218 | + { 'c' , "\xe3\x81\x9d", "\xe3\x81\x9d" }, // "そ", "そ" | |
219 | + { 'C' , "\xe3\x81\x9d", "\xe3\x81\x9d" }, // "そ", "そ" | |
220 | + { 'v' , "\xe3\x81\xb2", "\xe3\x81\xb2" }, // "ひ", "ひ" | |
221 | + { 'V' , "\xe3\x81\xb2", "\xe3\x81\xb2" }, // "ひ", "ひ" | |
222 | + { 'b' , "\xe3\x81\x93", "\xe3\x81\x93" }, // "こ", "こ" | |
223 | + { 'B' , "\xe3\x81\x93", "\xe3\x81\x93" }, // "こ", "こ" | |
224 | + { 'n' , "\xe3\x81\xbf", "\xe3\x81\xbf" }, // "み", "み" | |
225 | + { 'N' , "\xe3\x81\xbf", "\xe3\x81\xbf" }, // "み", "み" | |
226 | + { 'm' , "\xe3\x82\x82", "\xe3\x82\x82" }, // "も", "も" | |
227 | + { 'M' , "\xe3\x82\x82", "\xe3\x82\x82" }, // "も", "も" | |
228 | + { ',' , "\xe3\x81\xad", "\xe3\x80\x81" }, // "ね", "、" | |
229 | + { '<' , "\xe3\x80\x81", "\xe3\x80\x81" }, // "、", "、" | |
230 | + { '.' , "\xe3\x82\x8b", "\xe3\x80\x82" }, // "る", "。" | |
231 | + { '>' , "\xe3\x80\x82", "\xe3\x80\x82" }, // "。", "。" | |
232 | + { '/' , "\xe3\x82\x81", "\xe3\x83\xbb" }, // "め", "・" | |
233 | + { '?' , "\xe3\x83\xbb", "\xe3\x83\xbb" }, // "・", "・" | |
234 | + { '_' , "\xe3\x82\x8d", "\xe3\x82\x8d" }, // "ろ", "ろ" | |
235 | + // uim distinguishes backslash key and yen key | |
236 | + { '\\', "\xe3\x82\x8d", "\xe3\x82\x8d" }, // "ろ", "ろ" | |
237 | + { UKey_Yen, "\xe3\x83\xbc", "\xe3\x83\xbc" }, // "ー", "ー" | |
238 | +}, kana_map_us[] = { | |
239 | + { '`' , "\xe3\x82\x8d", "\xe3\x82\x8d" }, // "ろ", "ろ" | |
240 | + { '~' , "\xe3\x82\x8d", "\xe3\x82\x8d" }, // "ろ", "ろ" | |
241 | + { '1' , "\xe3\x81\xac", "\xe3\x81\xac" }, // "ぬ", "ぬ" | |
242 | + { '!' , "\xe3\x81\xac", "\xe3\x81\xac" }, // "ぬ", "ぬ" | |
243 | + { '2' , "\xe3\x81\xb5", "\xe3\x81\xb5" }, // "ふ", "ふ" | |
244 | + { '@' , "\xe3\x81\xb5", "\xe3\x81\xb5" }, // "ふ", "ふ" | |
245 | + { '3' , "\xe3\x81\x82", "\xe3\x81\x81" }, // "あ", "ぁ" | |
246 | + { '#' , "\xe3\x81\x81", "\xe3\x81\x81" }, // "ぁ", "ぁ" | |
247 | + { '4' , "\xe3\x81\x86", "\xe3\x81\x85" }, // "う", "ぅ" | |
248 | + { '$' , "\xe3\x81\x85", "\xe3\x81\x85" }, // "ぅ", "ぅ" | |
249 | + { '5' , "\xe3\x81\x88", "\xe3\x81\x87" }, // "え", "ぇ" | |
250 | + { '%' , "\xe3\x81\x87", "\xe3\x81\x87" }, // "ぇ", "ぇ" | |
251 | + { '6' , "\xe3\x81\x8a", "\xe3\x81\x89" }, // "お", "ぉ" | |
252 | + { '^' , "\xe3\x81\x89", "\xe3\x81\x89" }, // "ぉ", "ぉ" | |
253 | + { '7' , "\xe3\x82\x84", "\xe3\x82\x83" }, // "や", "ゃ" | |
254 | + { '&' , "\xe3\x82\x83", "\xe3\x82\x83" }, // "ゃ", "ゃ" | |
255 | + { '8' , "\xe3\x82\x86", "\xe3\x82\x85" }, // "ゆ", "ゅ" | |
256 | + { '*' , "\xe3\x82\x85", "\xe3\x82\x85" }, // "ゅ", "ゅ" | |
257 | + { '9' , "\xe3\x82\x88", "\xe3\x82\x87" }, // "よ", "ょ" | |
258 | + { '(' , "\xe3\x82\x87", "\xe3\x82\x87" }, // "ょ", "ょ" | |
259 | + { '0' , "\xe3\x82\x8f", "\xe3\x82\x92" }, // "わ", "を" | |
260 | + { ')' , "\xe3\x82\x92", "\xe3\x82\x92" }, // "を", "を" | |
261 | + { '-' , "\xe3\x81\xbb", "\xe3\x83\xbc" }, // "ほ", "ー" | |
262 | + { '_' , "\xe3\x83\xbc", "\xe3\x83\xbc" }, // "ー", "ー" | |
263 | + { '=' , "\xe3\x81\xb8", "\xe3\x81\xb8" }, // "へ", "へ" | |
264 | + { '+' , "\xe3\x81\xb8", "\xe3\x81\xb8" }, // "へ", "へ" | |
265 | + { 'q' , "\xe3\x81\x9f", "\xe3\x81\x9f" }, // "た", "た" | |
266 | + { 'Q' , "\xe3\x81\x9f", "\xe3\x81\x9f" }, // "た", "た" | |
267 | + { 'w' , "\xe3\x81\xa6", "\xe3\x81\xa6" }, // "て", "て" | |
268 | + { 'W' , "\xe3\x81\xa6", "\xe3\x81\xa6" }, // "て", "て" | |
269 | + { 'e' , "\xe3\x81\x84", "\xe3\x81\x83" }, // "い", "ぃ" | |
270 | + { 'E' , "\xe3\x81\x83", "\xe3\x81\x83" }, // "ぃ", "ぃ" | |
271 | + { 'r' , "\xe3\x81\x99", "\xe3\x81\x99" }, // "す", "す" | |
272 | + { 'R' , "\xe3\x81\x99", "\xe3\x81\x99" }, // "す", "す" | |
273 | + { 't' , "\xe3\x81\x8b", "\xe3\x81\x8b" }, // "か", "か" | |
274 | + { 'T' , "\xe3\x81\x8b", "\xe3\x81\x8b" }, // "か", "か" | |
275 | + { 'y' , "\xe3\x82\x93", "\xe3\x82\x93" }, // "ん", "ん" | |
276 | + { 'Y' , "\xe3\x82\x93", "\xe3\x82\x93" }, // "ん", "ん" | |
277 | + { 'u' , "\xe3\x81\xaa", "\xe3\x81\xaa" }, // "な", "な" | |
278 | + { 'U' , "\xe3\x81\xaa", "\xe3\x81\xaa" }, // "な", "な" | |
279 | + { 'i' , "\xe3\x81\xab", "\xe3\x81\xab" }, // "に", "に" | |
280 | + { 'I' , "\xe3\x81\xab", "\xe3\x81\xab" }, // "に", "に" | |
281 | + { 'o' , "\xe3\x82\x89", "\xe3\x82\x89" }, // "ら", "ら" | |
282 | + { 'O' , "\xe3\x82\x89", "\xe3\x82\x89" }, // "ら", "ら" | |
283 | + { 'p' , "\xe3\x81\x9b", "\xe3\x81\x9b" }, // "せ", "せ" | |
284 | + { 'P' , "\xe3\x81\x9b", "\xe3\x81\x9b" }, // "せ", "せ" | |
285 | + { '[' , "\xe3\x82\x9b", "\xe3\x82\x9b" }, // "゛", "゛" | |
286 | + { '{' , "\xe3\x82\x9b", "\xe3\x82\x9b" }, // "゛", "゛" | |
287 | + { ']' , "\xe3\x82\x9c", "\xe3\x80\x8c" }, // "゜", "「" | |
288 | + { '}' , "\xe3\x80\x8c", "\xe3\x80\x8c" }, // "「", "「" | |
289 | + { '\\', "\xe3\x82\x80", "\xe3\x80\x8d" }, // "む", "」" | |
290 | + { '|' , "\xe3\x80\x8d", "\xe3\x80\x8d" }, // "」", "」" | |
291 | + { 'a' , "\xe3\x81\xa1", "\xe3\x81\xa1" }, // "ち", "ち" | |
292 | + { 'A' , "\xe3\x81\xa1", "\xe3\x81\xa1" }, // "ち", "ち" | |
293 | + { 's' , "\xe3\x81\xa8", "\xe3\x81\xa8" }, // "と", "と" | |
294 | + { 'S' , "\xe3\x81\xa8", "\xe3\x81\xa8" }, // "と", "と" | |
295 | + { 'd' , "\xe3\x81\x97", "\xe3\x81\x97" }, // "し", "し" | |
296 | + { 'D' , "\xe3\x81\x97", "\xe3\x81\x97" }, // "し", "し" | |
297 | + { 'f' , "\xe3\x81\xaf", "\xe3\x81\xaf" }, // "は", "は" | |
298 | + { 'F' , "\xe3\x81\xaf", "\xe3\x81\xaf" }, // "は", "は" | |
299 | + { 'g' , "\xe3\x81\x8d", "\xe3\x81\x8d" }, // "き", "き" | |
300 | + { 'G' , "\xe3\x81\x8d", "\xe3\x81\x8d" }, // "き", "き" | |
301 | + { 'h' , "\xe3\x81\x8f", "\xe3\x81\x8f" }, // "く", "く" | |
302 | + { 'H' , "\xe3\x81\x8f", "\xe3\x81\x8f" }, // "く", "く" | |
303 | + { 'j' , "\xe3\x81\xbe", "\xe3\x81\xbe" }, // "ま", "ま" | |
304 | + { 'J' , "\xe3\x81\xbe", "\xe3\x81\xbe" }, // "ま", "ま" | |
305 | + { 'k' , "\xe3\x81\xae", "\xe3\x81\xae" }, // "の", "の" | |
306 | + { 'K' , "\xe3\x81\xae", "\xe3\x81\xae" }, // "の", "の" | |
307 | + { 'l' , "\xe3\x82\x8a", "\xe3\x82\x8a" }, // "り", "り" | |
308 | + { 'L' , "\xe3\x82\x8a", "\xe3\x82\x8a" }, // "り", "り" | |
309 | + { ';' , "\xe3\x82\x8c", "\xe3\x82\x8c" }, // "れ", "れ" | |
310 | + { ':' , "\xe3\x82\x8c", "\xe3\x82\x8c" }, // "れ", "れ" | |
311 | + { '\'', "\xe3\x81\x91", "\xe3\x81\x91" }, // "け", "け" | |
312 | + { '\"', "\xe3\x81\x91", "\xe3\x81\x91" }, // "け", "け" | |
313 | + { 'z' , "\xe3\x81\xa4", "\xe3\x81\xa3" }, // "つ", "っ" | |
314 | + { 'Z' , "\xe3\x81\xa3", "\xe3\x81\xa3" }, // "っ", "っ" | |
315 | + { 'x' , "\xe3\x81\x95", "\xe3\x81\x95" }, // "さ", "さ" | |
316 | + { 'X' , "\xe3\x81\x95", "\xe3\x81\x95" }, // "さ", "さ" | |
317 | + { 'c' , "\xe3\x81\x9d", "\xe3\x81\x9d" }, // "そ", "そ" | |
318 | + { 'C' , "\xe3\x81\x9d", "\xe3\x81\x9d" }, // "そ", "そ" | |
319 | + { 'v' , "\xe3\x81\xb2", "\xe3\x81\xb2" }, // "ひ", "ひ" | |
320 | + { 'V' , "\xe3\x81\xb2", "\xe3\x81\xb2" }, // "ひ", "ひ" | |
321 | + { 'b' , "\xe3\x81\x93", "\xe3\x81\x93" }, // "こ", "こ" | |
322 | + { 'B' , "\xe3\x81\x93", "\xe3\x81\x93" }, // "こ", "こ" | |
323 | + { 'n' , "\xe3\x81\xbf", "\xe3\x81\xbf" }, // "み", "み" | |
324 | + { 'N' , "\xe3\x81\xbf", "\xe3\x81\xbf" }, // "み", "み" | |
325 | + { 'm' , "\xe3\x82\x82", "\xe3\x82\x82" }, // "も", "も" | |
326 | + { 'M' , "\xe3\x82\x82", "\xe3\x82\x82" }, // "も", "も" | |
327 | + { ',' , "\xe3\x81\xad", "\xe3\x80\x81" }, // "ね", "、" | |
328 | + { '<' , "\xe3\x80\x81", "\xe3\x80\x81" }, // "、", "、" | |
329 | + { '.' , "\xe3\x82\x8b", "\xe3\x80\x82" }, // "る", "。" | |
330 | + { '>' , "\xe3\x80\x82", "\xe3\x80\x82" }, // "。", "。" | |
331 | + { '/' , "\xe3\x82\x81", "\xe3\x83\xbb" }, // "め", "・" | |
332 | + { '?' , "\xe3\x83\xbb", "\xe3\x83\xbb" }, // "・", "・" | |
333 | + { UKey_Yen, "\xe3\x83\xbc", "\xe3\x83\xbc" }, // "ー", "ー" | |
334 | +}; | |
335 | + | |
336 | +} // namespace | |
337 | + | |
338 | +namespace mozc { | |
339 | +namespace uim { | |
340 | + | |
341 | +KeyTranslator::KeyTranslator() { | |
342 | + Init(); | |
343 | +} | |
344 | + | |
345 | +KeyTranslator::~KeyTranslator() { | |
346 | +} | |
347 | + | |
348 | +bool KeyTranslator::Translate(unsigned int keyval, | |
349 | + unsigned int keycode, | |
350 | + unsigned int modifiers, | |
351 | + config::Config::PreeditMethod method, | |
352 | + bool layout_is_jp, | |
353 | + commands::KeyEvent *out_event) const { | |
354 | + DCHECK(out_event) << "out_event is NULL"; | |
355 | + out_event->Clear(); | |
356 | + | |
357 | + string kana_key_string; | |
358 | + if ((method == config::Config::KANA) && IsKanaAvailable( | |
359 | + keyval, keycode, modifiers, layout_is_jp, &kana_key_string)) { | |
360 | + out_event->set_key_code(keyval); | |
361 | + out_event->set_key_string(kana_key_string); | |
362 | + } else if (IsAscii(keyval, keycode, modifiers)) { | |
363 | + out_event->set_key_code(keyval); | |
364 | + } else if (IsModifierKey(keyval, keycode, modifiers)) { | |
365 | + ModifierKeyMap::const_iterator i = modifier_key_map_.find(keyval); | |
366 | + DCHECK(i != modifier_key_map_.end()); | |
367 | + out_event->add_modifier_keys((*i).second); | |
368 | + } else if (IsSpecialKey(keyval, keycode, modifiers)) { | |
369 | + SpecialKeyMap::const_iterator i = special_key_map_.find(keyval); | |
370 | + DCHECK(i != special_key_map_.end()); | |
371 | + out_event->set_special_key((*i).second); | |
372 | + } else if ((method == config::Config::ROMAN) && keyval == UKey_Yen) { | |
373 | + /* regards yen key as backslash */ | |
374 | + out_event->set_key_code('\\'); | |
375 | + } else { | |
376 | + VLOG(1) << "Unknown keyval: " << keyval; | |
377 | + return false; | |
378 | + } | |
379 | + | |
380 | + for (ModifierKeyMap::const_iterator i = modifier_mask_map_.begin(); | |
381 | + i != modifier_mask_map_.end(); | |
382 | + ++i) { | |
383 | + // Do not set a SHIFT modifier when |keyval| is a printable key by following | |
384 | + // the Mozc's rule. | |
385 | + if (((*i).second == commands::KeyEvent::SHIFT) && | |
386 | + IsAscii(keyval, keycode, modifiers)) { | |
387 | + continue; | |
388 | + } | |
389 | + | |
390 | + if ((*i).first & modifiers) { | |
391 | + out_event->add_modifier_keys((*i).second); | |
392 | + } | |
393 | + } | |
394 | + | |
395 | + return true; | |
396 | +} | |
397 | + | |
398 | +void KeyTranslator::Init() { | |
399 | + for (int i = 0; i < arraysize(special_key_map); ++i) { | |
400 | + CHECK(special_key_map_.insert(make_pair(special_key_map[i].from, | |
401 | + special_key_map[i].to)).second); | |
402 | + } | |
403 | + for (int i = 0; i < arraysize(modifier_key_map); ++i) { | |
404 | + CHECK(modifier_key_map_.insert(make_pair(modifier_key_map[i].from, | |
405 | + modifier_key_map[i].to)).second); | |
406 | + } | |
407 | + for (int i = 0; i < arraysize(modifier_mask_map); ++i) { | |
408 | + CHECK(modifier_mask_map_.insert(make_pair(modifier_mask_map[i].from, | |
409 | + modifier_mask_map[i].to)).second); | |
410 | + } | |
411 | + for (int i = 0; i < arraysize(kana_map_jp); ++i) { | |
412 | + CHECK(kana_map_jp_.insert( | |
413 | + make_pair(kana_map_jp[i].code, make_pair( | |
414 | + kana_map_jp[i].no_shift, kana_map_jp[i].shift))).second); | |
415 | + } | |
416 | + for (int i = 0; i < arraysize(kana_map_us); ++i) { | |
417 | + CHECK(kana_map_us_.insert( | |
418 | + make_pair(kana_map_us[i].code, make_pair( | |
419 | + kana_map_us[i].no_shift, kana_map_us[i].shift))).second); | |
420 | + } | |
421 | +} | |
422 | + | |
423 | +bool KeyTranslator::IsModifierKey(unsigned int keyval, | |
424 | + unsigned int keycode, | |
425 | + unsigned int modifiers) const { | |
426 | + return modifier_key_map_.find(keyval) != modifier_key_map_.end(); | |
427 | +} | |
428 | + | |
429 | +bool KeyTranslator::IsSpecialKey(unsigned int keyval, | |
430 | + unsigned int keycode, | |
431 | + unsigned int modifiers) const { | |
432 | + return special_key_map_.find(keyval) != special_key_map_.end(); | |
433 | +} | |
434 | + | |
435 | +bool KeyTranslator::IsKanaAvailable(unsigned int keyval, | |
436 | + unsigned int keycode, | |
437 | + unsigned int modifiers, | |
438 | + bool layout_is_jp, | |
439 | + string *out) const { | |
440 | + if ((modifiers & UMod_Control) || (modifiers & UMod_Alt)) { | |
441 | + return false; | |
442 | + } | |
443 | + const KanaMap &kana_map = layout_is_jp ? kana_map_jp_ : kana_map_us_; | |
444 | + KanaMap::const_iterator iter = kana_map.find(keyval); | |
445 | + if (iter == kana_map.end()) { | |
446 | + return false; | |
447 | + } | |
448 | + | |
449 | + if (out) | |
450 | + *out = (modifiers & UMod_Shift) ? | |
451 | + iter->second.second : iter->second.first; | |
452 | + | |
453 | + return true; | |
454 | +} | |
455 | + | |
456 | +bool KeyTranslator::IsAscii(unsigned int keyval, | |
457 | + unsigned int keycode, | |
458 | + unsigned int modifiers) { | |
459 | + return (keyval > 0x20 && | |
460 | + // Note: Space key (0x20) is a special key in Mozc. | |
461 | + keyval <= 0x7e); // ~ | |
462 | +} | |
463 | + | |
464 | +} // namespace uim | |
465 | +} // namespace mozc | |
466 | diff --git a/unix/uim/key_translator.h b/unix/uim/key_translator.h | |
467 | new file mode 100644 | |
468 | index 0000000..ffe8235 | |
469 | --- /dev/null | |
470 | +++ b/unix/uim/key_translator.h | |
471 | @@ -0,0 +1,110 @@ | |
472 | +// Copyright 2010, Google Inc. | |
473 | +// All rights reserved. | |
474 | +// | |
475 | +// Redistribution and use in source and binary forms, with or without | |
476 | +// modification, are permitted provided that the following conditions are | |
477 | +// met: | |
478 | +// | |
479 | +// * Redistributions of source code must retain the above copyright | |
480 | +// notice, this list of conditions and the following disclaimer. | |
481 | +// * Redistributions in binary form must reproduce the above | |
482 | +// copyright notice, this list of conditions and the following disclaimer | |
483 | +// in the documentation and/or other materials provided with the | |
484 | +// distribution. | |
485 | +// * Neither the name of Google Inc. nor the names of its | |
486 | +// contributors may be used to endorse or promote products derived from | |
487 | +// this software without specific prior written permission. | |
488 | +// | |
489 | +// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS | |
490 | +// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT | |
491 | +// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR | |
492 | +// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT | |
493 | +// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, | |
494 | +// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT | |
495 | +// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, | |
496 | +// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY | |
497 | +// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT | |
498 | +// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE | |
499 | +// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. | |
500 | + | |
501 | +#ifndef MOZC_UNIX_UIM_KEY_TRANSLATOR_H_ | |
502 | +#define MOZC_UNIX_UIM_KEY_TRANSLATOR_H_ | |
503 | + | |
504 | +#include <uim.h> | |
505 | + | |
506 | +#include <map> | |
507 | +#include <ext/hash_map> | |
508 | +using __gnu_cxx::hash_map; | |
509 | + | |
510 | +#include "base/base.h" | |
511 | +#include "session/commands.pb.h" | |
512 | + | |
513 | +namespace mozc { | |
514 | +namespace uim { | |
515 | + | |
516 | +// This class is responsible for converting key code sent from ibus-daemon | |
517 | +// (defined in /usr/include/ibus-1.0/ibuskeysyms.h) to a KeyEvent object for | |
518 | +// the input of session_interface. | |
519 | +class KeyTranslator { | |
520 | + public: | |
521 | + KeyTranslator(); | |
522 | + virtual ~KeyTranslator(); | |
523 | + | |
524 | + // Converts ibus keycode to Mozc key code and stores them on |out_event|. | |
525 | + // Returns true if ibus keycode is successfully converted to Mozc key code. | |
526 | + bool Translate(unsigned int keyval, | |
527 | + unsigned int keycode, | |
528 | + unsigned int modifiers, | |
529 | + config::Config::PreeditMethod method, | |
530 | + bool layout_is_jp, | |
531 | + commands::KeyEvent *out_event) const; | |
532 | + | |
533 | + private: | |
534 | + typedef hash_map<unsigned int, commands::KeyEvent::SpecialKey> SpecialKeyMap; | |
535 | + typedef map<unsigned int, commands::KeyEvent::ModifierKey> ModifierKeyMap; | |
536 | + typedef map<unsigned int, pair<string, string> > KanaMap; | |
537 | + | |
538 | + // Returns true iff key is modifier key such as SHIFT, ALT, or CAPSLOCK. | |
539 | + bool IsModifierKey(unsigned int keyval, | |
540 | + unsigned int keycode, | |
541 | + unsigned int modifiers) const; | |
542 | + | |
543 | + // Returns true iff key is special key such as ENTER, ESC, or PAGE_UP. | |
544 | + bool IsSpecialKey(unsigned int keyval, | |
545 | + unsigned int keycode, | |
546 | + unsigned int modifiers) const; | |
547 | + // Returns true iff |keyval| is a key with a kana assigned. | |
548 | + bool IsKanaAvailable(unsigned int keyval, | |
549 | + unsigned int keycode, | |
550 | + unsigned int modifiers, | |
551 | + bool layout_is_jp, | |
552 | + string *out) const; | |
553 | + | |
554 | + | |
555 | + // Returns true iff key is ASCII such as '0', 'A', or '!'. | |
556 | + static bool IsAscii(unsigned int keyval, | |
557 | + unsigned int keycode, | |
558 | + unsigned int modifiers); | |
559 | + | |
560 | + // Initializes private fields. | |
561 | + void Init(); | |
562 | + | |
563 | + // Stores a mapping from ibus keys to Mozc's special keys. | |
564 | + SpecialKeyMap special_key_map_; | |
565 | + // Stores a mapping from ibus modifier keys to Mozc's modifier keys. | |
566 | + ModifierKeyMap modifier_key_map_; | |
567 | + // Stores a mapping from ibus modifier masks to Mozc's modifier keys. | |
568 | + ModifierKeyMap modifier_mask_map_; | |
569 | + // Stores a mapping from ASCII to Kana character. For example, ASCII character | |
570 | + // '4' is mapped to Japanese 'Hiragana Letter U' (without Shift modifier) and | |
571 | + // 'Hiragana Letter Small U' (with Shift modifier). | |
572 | + KanaMap kana_map_jp_; // mapping for JP keyboard. | |
573 | + KanaMap kana_map_us_; // mapping for US keyboard. | |
574 | + | |
575 | + DISALLOW_COPY_AND_ASSIGN(KeyTranslator); | |
576 | +}; | |
577 | + | |
578 | +} // namespace uim | |
579 | +} // namespace mozc | |
580 | + | |
581 | +#endif // MOZC_UNIX_UIM_KEY_TRANSLATOR_H_ | |
582 | diff --git a/unix/uim/mozc.cc b/unix/uim/mozc.cc | |
583 | new file mode 100644 | |
584 | index 0000000..0afa2f6 | |
585 | --- /dev/null | |
586 | +++ b/unix/uim/mozc.cc | |
587 | @@ -0,0 +1,994 @@ | |
588 | +/* | |
589 | + | |
590 | + Copyright (c) 2010 uim Project http://code.google.com/p/uim/ | |
591 | + | |
592 | + All rights reserved. | |
593 | + | |
594 | + Redistribution and use in source and binary forms, with or without | |
595 | + modification, are permitted provided that the following conditions | |
596 | + are met: | |
597 | + | |
598 | + 1. Redistributions of source code must retain the above copyright | |
599 | + notice, this list of conditions and the following disclaimer. | |
600 | + 2. Redistributions in binary form must reproduce the above copyright | |
601 | + notice, this list of conditions and the following disclaimer in the | |
602 | + documentation and/or other materials provided with the distribution. | |
603 | + 3. Neither the name of authors nor the names of its contributors | |
604 | + may be used to endorse or promote products derived from this software | |
605 | + without specific prior written permission. | |
606 | + | |
607 | + THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS ``AS IS'' AND | |
608 | + ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE | |
609 | + IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE | |
610 | + ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDERS OR CONTRIBUTORS BE LIABLE | |
611 | + FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL | |
612 | + DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS | |
613 | + OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) | |
614 | + HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT | |
615 | + LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY | |
616 | + OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF | |
617 | + SUCH DAMAGE. | |
618 | + | |
619 | +*/ | |
620 | + | |
621 | +//#include <config.h> | |
622 | + | |
623 | +#include <stdio.h> | |
624 | +#include <stdlib.h> | |
625 | +#include <string.h> | |
626 | +#include <ctype.h> | |
627 | + | |
628 | +#include "uim.h" | |
629 | +#include "uim-scm.h" | |
630 | +#include "uim-scm-abbrev.h" | |
631 | +#include "uim-util.h" | |
632 | +#if (UIM_VERSION_MAJOR >= 1 && UIM_VERSION_MINOR >= 6) || (UIM_VERSION_MAJOR >= 2) | |
633 | +# include "dynlib.h" | |
634 | +#else | |
635 | +# include "plugin.h" | |
636 | +#endif | |
637 | + | |
638 | +#include "base/base.h" | |
639 | +#include "base/util.h" | |
640 | +#include "base/scoped_ptr.h" | |
641 | +#include "session/config.pb.h" | |
642 | +#include "session/commands.pb.h" | |
643 | +#include "client/session.h" | |
644 | +#include "unix/uim/key_translator.h" | |
645 | + | |
646 | +// use server/client session | |
647 | +#include "base/util.h" | |
648 | +#include "client/session.h" | |
649 | + | |
650 | +#define USE_CASCADING_CANDIDATES 0 | |
651 | + | |
652 | +#include <map> | |
653 | +#include <ext/hash_map> | |
654 | +using __gnu_cxx::hash_map; | |
655 | +static char **argv; | |
656 | + | |
657 | +// for every 5 minutes, call SyncData | |
658 | +const uint64 kSyncDataInterval = 5 * 60; | |
659 | +// An ID for a candidate which is not associated with a text. | |
660 | +const int32 kBadCandidateId = -1; | |
661 | + | |
662 | +uint64 GetTime() { | |
663 | + return static_cast<uint64>(time(NULL)); | |
664 | +} | |
665 | + | |
666 | +namespace mozc { | |
667 | + | |
668 | +namespace client { | |
669 | +class SessionInterface; | |
670 | +} | |
671 | +namespace uim { | |
672 | + | |
673 | +static int nr_contexts; | |
674 | +static struct context_slot_ { | |
675 | + client::SessionInterface *session; | |
676 | + KeyTranslator *keyTranslator; | |
677 | + commands::Output *output; | |
678 | + commands::CompositionMode currentMode; | |
679 | + bool has_preedit_before; | |
680 | + int cand_nr_before; | |
681 | + uint64 last_sync_time; | |
682 | +#if USE_CASCADING_CANDIDATES | |
683 | + vector<int32> *unique_candidate_ids; | |
684 | +#endif | |
685 | + config::Config::PreeditMethod preedit_method; | |
686 | +} *context_slot; | |
687 | + | |
688 | +static int | |
689 | +unused_context_id(void) | |
690 | +{ | |
691 | + int i; | |
692 | + | |
693 | + for (i = 0; i < nr_contexts; i++) { | |
694 | + if (!context_slot[i].session) | |
695 | + return i; | |
696 | + } | |
697 | + | |
698 | + nr_contexts++; | |
699 | + context_slot = (context_slot_ *)uim_realloc(context_slot, sizeof(struct context_slot_) * (nr_contexts)); | |
700 | + | |
701 | + return i; | |
702 | +} | |
703 | + | |
704 | +static void | |
705 | +SyncData(int id, bool force) | |
706 | +{ | |
707 | + if (context_slot[id].session == NULL) | |
708 | + return; | |
709 | + | |
710 | + const uint64 current_time = GetTime(); | |
711 | + if (force || | |
712 | + (current_time >= context_slot[id].last_sync_time && | |
713 | + current_time - context_slot[id].last_sync_time >= kSyncDataInterval)) { | |
714 | + context_slot[id].session->SyncData(); | |
715 | + context_slot[id].last_sync_time = current_time; | |
716 | + } | |
717 | +} | |
718 | + | |
719 | +static void | |
720 | +update_result(uim_lisp mc_, int id) | |
721 | +{ | |
722 | + commands::Output *output = context_slot[id].output; | |
723 | + | |
724 | + if (!output->has_result()) | |
725 | + return; | |
726 | + | |
727 | + const char *str = output->result().value().c_str(); | |
728 | + uim_scm_callf("im-commit", "os", mc_, str); | |
729 | +} | |
730 | + | |
731 | +static uim_lisp | |
732 | +insert_cursor(uim_lisp segs, const commands::Preedit::Segment &segment, int attr, int pos) | |
733 | +{ | |
734 | + size_t len = segment.value_length(); | |
735 | + | |
736 | + string former = Util::SubString(segment.value(), 0, pos); | |
737 | + string latter = Util::SubString(segment.value(), pos, len); | |
738 | + | |
739 | + uim_lisp seg_f, seg_c, seg_l; | |
740 | + if (pos == 0) { | |
741 | + seg_f = uim_scm_null(); /* not used */ | |
742 | + seg_c = CONS(MAKE_INT(UPreeditAttr_Cursor), MAKE_STR("")); | |
743 | + seg_l = CONS(MAKE_INT(attr), MAKE_STR(latter.c_str())); | |
744 | + | |
745 | + segs = CONS(seg_c, segs); | |
746 | + segs = CONS(seg_l, segs); | |
747 | + } else { | |
748 | + seg_f = CONS(MAKE_INT(attr), MAKE_STR(former.c_str())); | |
749 | + seg_c = CONS(MAKE_INT(UPreeditAttr_Cursor), MAKE_STR("")); | |
750 | + seg_l = CONS(MAKE_INT(attr), MAKE_STR(latter.c_str())); | |
751 | + | |
752 | + segs = CONS(seg_f, segs); | |
753 | + segs = CONS(seg_c, segs); | |
754 | + segs = CONS(seg_l, segs); | |
755 | + } | |
756 | + | |
757 | + return segs; | |
758 | +} | |
759 | + | |
760 | +static uim_lisp | |
761 | +compose_preedit(const commands::Output *output) | |
762 | +{ | |
763 | + const commands::Preedit &preedit = output->preedit(); | |
764 | + uim_lisp segs = uim_scm_null(); | |
765 | + uim_lisp separator = uim_scm_callf("mozc-separator", ""); | |
766 | + int cursorPos; | |
767 | + int count = 0; | |
768 | + int seg_count = preedit.segment_size(); | |
769 | + | |
770 | + cursorPos = output->preedit().cursor(); | |
771 | + | |
772 | + for (int i = 0; i < seg_count; ++i) { | |
773 | + const commands::Preedit::Segment segment = preedit.segment(i); | |
774 | + const char *str = segment.value().c_str(); | |
775 | + int attr; | |
776 | + int prev_count = count; | |
777 | + uim_lisp seg; | |
778 | + count += segment.value_length(); | |
779 | + | |
780 | + switch (segment.annotation()) { | |
781 | + case commands::Preedit::Segment::NONE: | |
782 | + attr = UPreeditAttr_None; | |
783 | + break; | |
784 | + case commands::Preedit::Segment::UNDERLINE: | |
785 | + attr = UPreeditAttr_UnderLine; | |
786 | + break; | |
787 | + case commands::Preedit::Segment::HIGHLIGHT: | |
788 | + attr = UPreeditAttr_Reverse | UPreeditAttr_Cursor; | |
789 | + break; | |
790 | + default: | |
791 | + attr = UPreeditAttr_None; | |
792 | + break; | |
793 | + } | |
794 | + | |
795 | + if (((prev_count < cursorPos) && (count > cursorPos)) || cursorPos == 0) { | |
796 | + uim_lisp new_segs; | |
797 | + if ((new_segs = insert_cursor(segs, segment, attr, cursorPos - prev_count)) != uim_scm_null()) { | |
798 | + segs = new_segs; | |
799 | + continue; | |
800 | + } | |
801 | + } | |
802 | + | |
803 | + seg = CONS(MAKE_INT(attr), MAKE_STR(str)); | |
804 | + | |
805 | + if (TRUEP(separator) && i > 0) | |
806 | + segs = CONS(separator, segs); | |
807 | + segs = CONS(seg, segs); | |
808 | + | |
809 | + if (count == cursorPos && !output->preedit().has_highlighted_position()) { | |
810 | + seg = CONS(MAKE_INT(UPreeditAttr_Cursor), MAKE_STR("")); | |
811 | + segs = CONS(seg, segs); | |
812 | + } | |
813 | + } | |
814 | + | |
815 | + return uim_scm_callf("reverse", "o", segs); | |
816 | +} | |
817 | + | |
818 | +static void | |
819 | +update_preedit(uim_lisp mc_, int id) | |
820 | +{ | |
821 | + uim_lisp preedit; | |
822 | + commands::Output *output = context_slot[id].output; | |
823 | + | |
824 | + if (!output->has_preedit()) { | |
825 | + if (context_slot[id].has_preedit_before) { | |
826 | + uim_scm_callf("context-update-preedit", "oo", mc_, uim_scm_null()); | |
827 | + } | |
828 | + context_slot[id].has_preedit_before = false; | |
829 | + | |
830 | + return; | |
831 | + } else { | |
832 | + preedit = compose_preedit(output); | |
833 | + context_slot[id].has_preedit_before = true; | |
834 | + } | |
835 | + uim_scm_callf("context-update-preedit", "oo", mc_, preedit); | |
836 | +} | |
837 | + | |
838 | +static void | |
839 | +update_candidates(uim_lisp mc_, int id) | |
840 | +{ | |
841 | + commands::Output *output = context_slot[id].output; | |
842 | + | |
843 | + if (!output->has_candidates()) { | |
844 | + uim_scm_callf("im-deactivate-candidate-selector", "o", mc_); | |
845 | + context_slot[id].cand_nr_before = 0; | |
846 | + | |
847 | + return; | |
848 | + } | |
849 | + | |
850 | + const commands::Candidates &candidates = output->candidates(); | |
851 | + bool first_time = false; | |
852 | + | |
853 | + if ((context_slot[id].cand_nr_before != candidates.size()) || !candidates.focused_index()) | |
854 | + first_time = true; | |
855 | + | |
856 | + if (first_time) | |
857 | + uim_scm_callf("im-activate-candidate-selector", "oii", mc_, candidates.size(), 9); | |
858 | + | |
859 | + if (candidates.has_focused_index()) { | |
860 | + int index = candidates.focused_index(); | |
861 | + uim_scm_callf("im-select-candidate", "oi", mc_, index); | |
862 | + } | |
863 | + context_slot[id].cand_nr_before = candidates.size(); | |
864 | + | |
865 | +#if USE_CASCADING_CANDIDATES | |
866 | + if (first_time || (candidates.has_focused_index() && candidates.focused_index() % 9 == 0)) { | |
867 | + context_slot[id].unique_candidate_ids->clear(); | |
868 | + for (int i = 0; i < candidates.candidate_size(); ++i) { | |
869 | + if (candidates.candidate(i).has_id()) { | |
870 | + const int32 cand_id = candidates.candidate(i).id(); | |
871 | + context_slot[id].unique_candidate_ids->push_back(cand_id); | |
872 | + } else { | |
873 | + // The parent node of the cascading window does not have an id since the | |
874 | + // node does not contain a candidate word. | |
875 | + context_slot[id].unique_candidate_ids->push_back(kBadCandidateId); | |
876 | + } | |
877 | + } | |
878 | + } | |
879 | +#endif | |
880 | +} | |
881 | + | |
882 | +static void | |
883 | +update_composition_mode(uim_lisp mc_, int id) | |
884 | +{ | |
885 | + commands::Output *output = context_slot[id].output; | |
886 | + | |
887 | + if (!output->has_mode()) | |
888 | + return; | |
889 | + | |
890 | + const commands::CompositionMode newMode = output->mode(); | |
891 | + if (context_slot[id].currentMode == newMode) | |
892 | + return; | |
893 | + | |
894 | + context_slot[id].currentMode = newMode; | |
895 | +} | |
896 | + | |
897 | +static void | |
898 | +update_all(uim_lisp mc_, int id) | |
899 | +{ | |
900 | + update_result(mc_, id); | |
901 | + update_preedit(mc_, id); | |
902 | + update_candidates(mc_, id); | |
903 | + update_composition_mode(mc_, id); | |
904 | +} | |
905 | + | |
906 | +static uim_lisp | |
907 | +create_context(uim_lisp mc_) | |
908 | +{ | |
909 | + int id; | |
910 | + | |
911 | + client::SessionInterface *session = new client::Session; | |
912 | + KeyTranslator *keyTranslator = new KeyTranslator; | |
913 | + commands::Output *output = new commands::Output; | |
914 | + | |
915 | + id = unused_context_id(); | |
916 | + context_slot[id].session = session; | |
917 | + context_slot[id].keyTranslator = keyTranslator; | |
918 | + context_slot[id].output = output; | |
919 | + context_slot[id].currentMode = commands::HIRAGANA; | |
920 | + context_slot[id].has_preedit_before = false; | |
921 | + context_slot[id].cand_nr_before = 0; | |
922 | +#if USE_CASCADING_CANDIDATES | |
923 | + context_slot[id].unique_candidate_ids = new vector<int32>; | |
924 | +#endif | |
925 | + | |
926 | + // Launch mozc_server | |
927 | + // or should I call this with mozc-on-key? | |
928 | + session->EnsureConnection(); | |
929 | +#if !USE_CASCADING_CANDIDATES | |
930 | + session->EnableCascadingWindow(false); | |
931 | +#endif | |
932 | + | |
933 | + return MAKE_INT(id); | |
934 | +} | |
935 | + | |
936 | +static uim_lisp | |
937 | +release_context(uim_lisp id_) | |
938 | +{ | |
939 | + int id = C_INT(id_); | |
940 | + | |
941 | + if (id < nr_contexts) { | |
942 | + SyncData(id, true); | |
943 | + delete context_slot[id].session; | |
944 | + delete context_slot[id].keyTranslator; | |
945 | + delete context_slot[id].output; | |
946 | +#if USE_CASCADING_CANDIDATES | |
947 | + delete context_slot[id].unique_candidate_ids; | |
948 | +#endif | |
949 | + context_slot[id].session = NULL; | |
950 | + context_slot[id].keyTranslator = NULL; | |
951 | + context_slot[id].output = NULL; | |
952 | + } | |
953 | + | |
954 | + return uim_scm_f(); | |
955 | +} | |
956 | + | |
957 | +static uim_lisp | |
958 | +reset_context(uim_lisp id_) | |
959 | +{ | |
960 | + return uim_scm_t(); | |
961 | +} | |
962 | + | |
963 | +static uim_lisp | |
964 | +press_key(uim_lisp mc_, uim_lisp id_, uim_lisp key_, uim_lisp state_) | |
965 | +{ | |
966 | + client::SessionInterface *session; | |
967 | + KeyTranslator *keyTranslator; | |
968 | + commands::KeyEvent key; | |
969 | + int id; | |
970 | + int keyval, keycode, modifiers; | |
971 | + config::Config::PreeditMethod preedit_method; | |
972 | + char *keyboard; | |
973 | + bool layout_is_jp; | |
974 | + | |
975 | + id = C_INT(id_); | |
976 | + session = context_slot[id].session; | |
977 | + keyTranslator = context_slot[id].keyTranslator; | |
978 | + preedit_method = context_slot[id].preedit_method; | |
979 | + keyboard = uim_scm_symbol_value_str("mozc-keyboard-type-for-kana-input-method"); | |
980 | + layout_is_jp = keyboard && !strcmp(keyboard, "jp-keyboard") ? true : false; | |
981 | + free(keyboard); | |
982 | + | |
983 | + keyval = C_INT(key_); | |
984 | + modifiers = C_INT(state_); | |
985 | + keycode = 0; /* XXX */ | |
986 | + | |
987 | + if (!(*keyTranslator).Translate(keyval, keycode, modifiers, preedit_method, layout_is_jp, &key)) | |
988 | + return uim_scm_f(); | |
989 | + | |
990 | + if (!(*session).SendKey(key, context_slot[id].output)) | |
991 | + return uim_scm_f(); | |
992 | + | |
993 | + update_all(mc_, id); | |
994 | + | |
995 | + const bool consumed = context_slot[id].output->consumed(); | |
996 | +#if 0 | |
997 | + fprintf(stderr, "debugstring %s\n", output.DebugString().c_str()); | |
998 | + fprintf(stderr, "consumed %d\n", consumed ? 1 : 0); | |
999 | +#endif | |
1000 | + | |
1001 | + return consumed ? uim_scm_t() : uim_scm_f(); | |
1002 | +} | |
1003 | + | |
1004 | +static uim_lisp | |
1005 | +release_key(uim_lisp id_, uim_lisp key_, uim_lisp state_) | |
1006 | +{ | |
1007 | + return uim_scm_f(); | |
1008 | +} | |
1009 | + | |
1010 | +static uim_lisp | |
1011 | +get_nr_candidates(uim_lisp id_) | |
1012 | +{ | |
1013 | + int id = C_INT(id_); | |
1014 | + commands::Output *output = context_slot[id].output; | |
1015 | + | |
1016 | + return MAKE_INT(output->candidates().size()); | |
1017 | +} | |
1018 | + | |
1019 | +static uim_lisp | |
1020 | +get_nth_candidate(uim_lisp id_, uim_lisp nth_) | |
1021 | +{ | |
1022 | + int id = C_INT(id_); | |
1023 | + commands::Output *output = context_slot[id].output; | |
1024 | + const commands::Candidates &candidates = output->candidates(); | |
1025 | + const char *cand; | |
1026 | + | |
1027 | + int nth; | |
1028 | + int idx; | |
1029 | + int nr; | |
1030 | + | |
1031 | + nth = C_INT(nth_); | |
1032 | + nr = candidates.size(); | |
1033 | + | |
1034 | + if (nth < nr) { | |
1035 | + idx = nth % 9; | |
1036 | + cand = candidates.candidate(idx).value().c_str(); | |
1037 | + } else | |
1038 | + cand = ""; | |
1039 | + | |
1040 | + return MAKE_STR(cand); | |
1041 | +} | |
1042 | + | |
1043 | +static uim_lisp | |
1044 | +get_nth_label(uim_lisp id_, uim_lisp nth_) | |
1045 | +{ | |
1046 | + int id = C_INT(id_); | |
1047 | + commands::Output *output = context_slot[id].output; | |
1048 | + const commands::Candidates &candidates = output->candidates(); | |
1049 | + const char *label; | |
1050 | + | |
1051 | + int nth; | |
1052 | + int idx; | |
1053 | + int nr; | |
1054 | + | |
1055 | + nth = C_INT(nth_); | |
1056 | + nr = candidates.size(); | |
1057 | + | |
1058 | + if (nth < nr) { | |
1059 | + idx = nth % 9; | |
1060 | + label = candidates.candidate(idx).annotation().shortcut().c_str(); | |
1061 | + } else | |
1062 | + label = ""; | |
1063 | + | |
1064 | + return MAKE_STR(label); | |
1065 | +} | |
1066 | + | |
1067 | +static uim_lisp | |
1068 | +get_nth_annotation(uim_lisp id_, uim_lisp nth_) | |
1069 | +{ | |
1070 | + int id = C_INT(id_); | |
1071 | + commands::Output *output = context_slot[id].output; | |
1072 | + const commands::Candidates &candidates = output->candidates(); | |
1073 | + const char *annotation; | |
1074 | + | |
1075 | + int nth; | |
1076 | + int idx; | |
1077 | + int nr; | |
1078 | + | |
1079 | + nth = C_INT(nth_); | |
1080 | + nr = candidates.size(); | |
1081 | + | |
1082 | + if (nth < nr) { | |
1083 | + idx = nth % 9; | |
1084 | + annotation = candidates.candidate(idx).annotation().description().c_str(); | |
1085 | + } else | |
1086 | + annotation = ""; | |
1087 | + | |
1088 | + return MAKE_STR(annotation); | |
1089 | +} | |
1090 | + | |
1091 | +/* from uim-key.c */ | |
1092 | +static struct key_entry { | |
1093 | + int key; | |
1094 | + const char *str; | |
1095 | +} key_tab[] = { | |
1096 | + {UKey_Yen, "yen"}, | |
1097 | + {UKey_Backspace, "backspace"}, | |
1098 | + {UKey_Delete, "delete"}, | |
1099 | + {UKey_Escape, "escape"}, | |
1100 | + {UKey_Return, "return"}, | |
1101 | + {UKey_Tab, "tab"}, | |
1102 | + {UKey_Left, "left"}, | |
1103 | + {UKey_Up, "up"}, | |
1104 | + {UKey_Right, "right"}, | |
1105 | + {UKey_Down, "down"}, | |
1106 | + {UKey_Prior, "prior"}, | |
1107 | + {UKey_Next, "next"}, | |
1108 | + {UKey_Home, "home"}, | |
1109 | + {UKey_End, "end"}, | |
1110 | + {UKey_Insert, "insert"}, | |
1111 | + {UKey_Multi_key, "Multi_key"}, | |
1112 | + {UKey_Codeinput, "codeinput"}, | |
1113 | + {UKey_SingleCandidate, "single-candidate"}, | |
1114 | + {UKey_MultipleCandidate, "multiple-candidate"}, | |
1115 | + {UKey_PreviousCandidate, "previous-candidate"}, | |
1116 | + {UKey_Mode_switch, "Mode_switch"}, | |
1117 | + {UKey_Kanji, "Kanji"}, | |
1118 | + {UKey_Muhenkan, "Muhenkan"}, | |
1119 | + {UKey_Henkan_Mode, "Henkan_Mode"}, | |
1120 | + {UKey_Romaji, "romaji"}, | |
1121 | + {UKey_Hiragana, "hiragana"}, | |
1122 | + {UKey_Katakana, "katakana"}, | |
1123 | + {UKey_Hiragana_Katakana, "hiragana-katakana"}, | |
1124 | + {UKey_Zenkaku, "zenkaku"}, | |
1125 | + {UKey_Hankaku, "hankaku"}, | |
1126 | + {UKey_Zenkaku_Hankaku, "zenkaku-hankaku"}, | |
1127 | + {UKey_Touroku, "touroku"}, | |
1128 | + {UKey_Massyo, "massyo"}, | |
1129 | + {UKey_Kana_Lock, "kana-lock"}, | |
1130 | + {UKey_Kana_Shift, "kana-shift"}, | |
1131 | + {UKey_Eisu_Shift, "eisu-shift"}, | |
1132 | + {UKey_Eisu_toggle, "eisu-toggle"}, | |
1133 | + | |
1134 | + {UKey_Hangul, "hangul"}, | |
1135 | + {UKey_Hangul_Start, "hangul-start"}, | |
1136 | + {UKey_Hangul_End, "hangul-end"}, | |
1137 | + {UKey_Hangul_Hanja, "hangul-hanja"}, | |
1138 | + {UKey_Hangul_Jamo, "hangul-jamo"}, | |
1139 | + {UKey_Hangul_Romaja, "hangul-romaja"}, | |
1140 | + {UKey_Hangul_Codeinput, "hangul-codeinput"}, | |
1141 | + {UKey_Hangul_Jeonja, "hangul-jeonja"}, | |
1142 | + {UKey_Hangul_Banja, "hangul-banja"}, | |
1143 | + {UKey_Hangul_PreHanja, "hangul-prehanja"}, | |
1144 | + {UKey_Hangul_PostHanja, "hangul-posthanja"}, | |
1145 | + {UKey_Hangul_SingleCandidate, "hangul-single-candidate"}, | |
1146 | + {UKey_Hangul_MultipleCandidate, "hangul-multiple-candidate"}, | |
1147 | + {UKey_Hangul_PreviousCandidate, "hangul-previous-candidate"}, | |
1148 | + {UKey_Hangul_Special, "hangul-special"}, | |
1149 | + | |
1150 | + {UKey_F1, "F1"}, | |
1151 | + {UKey_F2, "F2"}, | |
1152 | + {UKey_F3, "F3"}, | |
1153 | + {UKey_F4, "F4"}, | |
1154 | + {UKey_F5, "F5"}, | |
1155 | + {UKey_F6, "F6"}, | |
1156 | + {UKey_F7, "F7"}, | |
1157 | + {UKey_F8, "F8"}, | |
1158 | + {UKey_F9, "F9"}, | |
1159 | + {UKey_F10, "F10"}, | |
1160 | + {UKey_F11, "F11"}, | |
1161 | + {UKey_F12, "F12"}, | |
1162 | + {UKey_F13, "F13"}, | |
1163 | + {UKey_F14, "F14"}, | |
1164 | + {UKey_F15, "F15"}, | |
1165 | + {UKey_F16, "F16"}, | |
1166 | + {UKey_F17, "F17"}, | |
1167 | + {UKey_F18, "F18"}, | |
1168 | + {UKey_F19, "F19"}, | |
1169 | + {UKey_F20, "F20"}, | |
1170 | + {UKey_F21, "F21"}, | |
1171 | + {UKey_F22, "F22"}, | |
1172 | + {UKey_F23, "F23"}, | |
1173 | + {UKey_F24, "F24"}, | |
1174 | + {UKey_F25, "F25"}, | |
1175 | + {UKey_F26, "F26"}, | |
1176 | + {UKey_F27, "F27"}, | |
1177 | + {UKey_F28, "F28"}, | |
1178 | + {UKey_F29, "F29"}, | |
1179 | + {UKey_F30, "F30"}, | |
1180 | + {UKey_F31, "F31"}, | |
1181 | + {UKey_F32, "F32"}, | |
1182 | + {UKey_F33, "F33"}, | |
1183 | + {UKey_F34, "F34"}, | |
1184 | + {UKey_F35, "F35"}, | |
1185 | + | |
1186 | + {UKey_Dead_Grave, "dead-grave"}, | |
1187 | + {UKey_Dead_Acute, "dead-acute"}, | |
1188 | + {UKey_Dead_Circumflex, "dead-circumflex"}, | |
1189 | + {UKey_Dead_Tilde, "dead-tilde"}, | |
1190 | + {UKey_Dead_Macron, "dead-macron"}, | |
1191 | + {UKey_Dead_Breve, "dead-breve"}, | |
1192 | + {UKey_Dead_Abovedot, "dead-abovedot"}, | |
1193 | + {UKey_Dead_Diaeresis, "dead-diaeresis"}, | |
1194 | + {UKey_Dead_Abovering, "dead-abovering"}, | |
1195 | + {UKey_Dead_Doubleacute, "dead-doubleacute"}, | |
1196 | + {UKey_Dead_Caron, "dead-caron"}, | |
1197 | + {UKey_Dead_Cedilla, "dead-cedilla"}, | |
1198 | + {UKey_Dead_Ogonek, "dead-ogonek"}, | |
1199 | + {UKey_Dead_Iota, "dead-iota"}, | |
1200 | + {UKey_Dead_VoicedSound, "dead-voiced-sound"}, | |
1201 | + {UKey_Dead_SemivoicedSound, "dead-semivoiced-sound"}, | |
1202 | + {UKey_Dead_Belowdot, "dead-belowdot"}, | |
1203 | + {UKey_Dead_Hook, "dead-hook"}, | |
1204 | + {UKey_Dead_Horn, "dead-horn"}, | |
1205 | + | |
1206 | + {UKey_Kana_Fullstop, "kana-fullstop"}, | |
1207 | + {UKey_Kana_OpeningBracket, "kana-opening-bracket"}, | |
1208 | + {UKey_Kana_ClosingBracket, "kana-closing-bracket"}, | |
1209 | + {UKey_Kana_Comma, "kana-comma"}, | |
1210 | + {UKey_Kana_Conjunctive, "kana-conjunctive"}, | |
1211 | + {UKey_Kana_WO, "kana-WO"}, | |
1212 | + {UKey_Kana_a, "kana-a"}, | |
1213 | + {UKey_Kana_i, "kana-i"}, | |
1214 | + {UKey_Kana_u, "kana-u"}, | |
1215 | + {UKey_Kana_e, "kana-e"}, | |
1216 | + {UKey_Kana_o, "kana-o"}, | |
1217 | + {UKey_Kana_ya, "kana-ya"}, | |
1218 | + {UKey_Kana_yu, "kana-yu"}, | |
1219 | + {UKey_Kana_yo, "kana-yo"}, | |
1220 | + {UKey_Kana_tsu, "kana-tsu"}, | |
1221 | + {UKey_Kana_ProlongedSound, "kana-prolonged-sound"}, | |
1222 | + {UKey_Kana_A, "kana-A"}, | |
1223 | + {UKey_Kana_I, "kana-I"}, | |
1224 | + {UKey_Kana_U, "kana-U"}, | |
1225 | + {UKey_Kana_E, "kana-E"}, | |
1226 | + {UKey_Kana_O, "kana-O"}, | |
1227 | + {UKey_Kana_KA, "kana-KA"}, | |
1228 | + {UKey_Kana_KI, "kana-KI"}, | |
1229 | + {UKey_Kana_KU, "kana-KU"}, | |
1230 | + {UKey_Kana_KE, "kana-KE"}, | |
1231 | + {UKey_Kana_KO, "kana-KO"}, | |
1232 | + {UKey_Kana_SA, "kana-SA"}, | |
1233 | + {UKey_Kana_SHI, "kana-SHI"}, | |
1234 | + {UKey_Kana_SU, "kana-SU"}, | |
1235 | + {UKey_Kana_SE, "kana-SE"}, | |
1236 | + {UKey_Kana_SO, "kana-SO"}, | |
1237 | + {UKey_Kana_TA, "kana-TA"}, | |
1238 | + {UKey_Kana_CHI, "kana-CHI"}, | |
1239 | + {UKey_Kana_TSU, "kana-TSU"}, | |
1240 | + {UKey_Kana_TE, "kana-TE"}, | |
1241 | + {UKey_Kana_TO, "kana-TO"}, | |
1242 | + {UKey_Kana_NA, "kana-NA"}, | |
1243 | + {UKey_Kana_NI, "kana-NI"}, | |
1244 | + {UKey_Kana_NU, "kana-NU"}, | |
1245 | + {UKey_Kana_NE, "kana-NE"}, | |
1246 | + {UKey_Kana_NO, "kana-NO"}, | |
1247 | + {UKey_Kana_HA, "kana-HA"}, | |
1248 | + {UKey_Kana_HI, "kana-HI"}, | |
1249 | + {UKey_Kana_FU, "kana-FU"}, | |
1250 | + {UKey_Kana_HE, "kana-HE"}, | |
1251 | + {UKey_Kana_HO, "kana-HO"}, | |
1252 | + {UKey_Kana_MA, "kana-MA"}, | |
1253 | + {UKey_Kana_MI, "kana-MI"}, | |
1254 | + {UKey_Kana_MU, "kana-MU"}, | |
1255 | + {UKey_Kana_ME, "kana-ME"}, | |
1256 | + {UKey_Kana_MO, "kana-MO"}, | |
1257 | + {UKey_Kana_YA, "kana-YA"}, | |
1258 | + {UKey_Kana_YU, "kana-YU"}, | |
1259 | + {UKey_Kana_YO, "kana-YO"}, | |
1260 | + {UKey_Kana_RA, "kana-RA"}, | |
1261 | + {UKey_Kana_RI, "kana-RI"}, | |
1262 | + {UKey_Kana_RU, "kana-RU"}, | |
1263 | + {UKey_Kana_RE, "kana-RE"}, | |
1264 | + {UKey_Kana_RO, "kana-RO"}, | |
1265 | + {UKey_Kana_WA, "kana-WA"}, | |
1266 | + {UKey_Kana_N, "kana-N"}, | |
1267 | + {UKey_Kana_VoicedSound, "kana-voiced-sound"}, | |
1268 | + {UKey_Kana_SemivoicedSound, "kana-semivoiced-sound"}, | |
1269 | + | |
1270 | + {UKey_Private1, "Private1"}, | |
1271 | + {UKey_Private2, "Private2"}, | |
1272 | + {UKey_Private3, "Private3"}, | |
1273 | + {UKey_Private4, "Private4"}, | |
1274 | + {UKey_Private5, "Private5"}, | |
1275 | + {UKey_Private6, "Private6"}, | |
1276 | + {UKey_Private7, "Private7"}, | |
1277 | + {UKey_Private8, "Private8"}, | |
1278 | + {UKey_Private9, "Private9"}, | |
1279 | + {UKey_Private10, "Private10"}, | |
1280 | + {UKey_Private11, "Private11"}, | |
1281 | + {UKey_Private12, "Private12"}, | |
1282 | + {UKey_Private13, "Private13"}, | |
1283 | + {UKey_Private14, "Private14"}, | |
1284 | + {UKey_Private15, "Private15"}, | |
1285 | + {UKey_Private16, "Private16"}, | |
1286 | + {UKey_Private17, "Private17"}, | |
1287 | + {UKey_Private18, "Private18"}, | |
1288 | + {UKey_Private19, "Private19"}, | |
1289 | + {UKey_Private20, "Private20"}, | |
1290 | + {UKey_Private21, "Private21"}, | |
1291 | + {UKey_Private22, "Private22"}, | |
1292 | + {UKey_Private23, "Private23"}, | |
1293 | + {UKey_Private24, "Private24"}, | |
1294 | + {UKey_Private25, "Private25"}, | |
1295 | + {UKey_Private26, "Private26"}, | |
1296 | + {UKey_Private27, "Private27"}, | |
1297 | + {UKey_Private28, "Private28"}, | |
1298 | + {UKey_Private29, "Private29"}, | |
1299 | + {UKey_Private30, "Private30"}, | |
1300 | + {UKey_Shift_key, "Shift_key"}, | |
1301 | + {UKey_Alt_key, "Alt_key"}, | |
1302 | + {UKey_Control_key, "Control_key"}, | |
1303 | + {UKey_Meta_key, "Meta_key"}, | |
1304 | + {UKey_Super_key, "Super_key"}, | |
1305 | + {UKey_Hyper_key, "Hyper_key"}, | |
1306 | + | |
1307 | + {UKey_Caps_Lock, "caps-lock"}, | |
1308 | + {UKey_Num_Lock, "num-lock"}, | |
1309 | + {UKey_Scroll_Lock, "scroll-lock"}, | |
1310 | + /* {UKey_Other, "other"},*/ | |
1311 | + {0, 0} | |
1312 | +}; | |
1313 | + | |
1314 | +struct eqstr | |
1315 | +{ | |
1316 | + bool operator()(const char* s1, const char* s2) const | |
1317 | + { | |
1318 | + return strcmp(s1, s2) == 0; | |
1319 | + } | |
1320 | +}; | |
1321 | + | |
1322 | +typedef hash_map<const char *, int, __gnu_cxx::hash<const char *>, eqstr> KeyMap; | |
1323 | +static KeyMap key_map; | |
1324 | + | |
1325 | +static void install_keymap(void) | |
1326 | +{ | |
1327 | + int i; | |
1328 | + | |
1329 | + for (i = 0; key_tab[i].key; i++) | |
1330 | + key_map.insert(make_pair(key_tab[i].str, key_tab[i].key)); | |
1331 | +} | |
1332 | + | |
1333 | +static uim_lisp | |
1334 | +keysym_to_int(uim_lisp sym_) | |
1335 | +{ | |
1336 | + const char *sym = uim_scm_refer_c_str(sym_); | |
1337 | + int key = 0; | |
1338 | + | |
1339 | + KeyMap::iterator it = key_map.find(sym); | |
1340 | + if (it != key_map.end()) | |
1341 | + key = it->second; | |
1342 | + | |
1343 | + return uim_scm_make_int(key); | |
1344 | +} | |
1345 | + | |
1346 | +static uim_lisp | |
1347 | +get_composition_mode(uim_lisp id_) | |
1348 | +{ | |
1349 | + int id = C_INT(id_); | |
1350 | + const commands::CompositionMode mode = context_slot[id].currentMode; | |
1351 | + int type = 0; | |
1352 | + | |
1353 | + switch (mode) { | |
1354 | + case commands::DIRECT: | |
1355 | + type = -1; | |
1356 | + break; | |
1357 | + case commands::HIRAGANA: | |
1358 | + type = 0; | |
1359 | + break; | |
1360 | + case commands::FULL_KATAKANA: | |
1361 | + type = 1; | |
1362 | + break; | |
1363 | + case commands::HALF_KATAKANA: | |
1364 | + type = 2; | |
1365 | + break; | |
1366 | + case commands::HALF_ASCII: | |
1367 | + type = 3; | |
1368 | + break; | |
1369 | + case commands::FULL_ASCII: | |
1370 | + type = 4; | |
1371 | + break; | |
1372 | + default: | |
1373 | + type = -1; | |
1374 | + break; | |
1375 | + } | |
1376 | + | |
1377 | + return MAKE_INT(type); | |
1378 | +} | |
1379 | + | |
1380 | +static uim_lisp | |
1381 | +set_composition_mode(uim_lisp mc_, uim_lisp id_, uim_lisp new_mode_) | |
1382 | +{ | |
1383 | + int id = C_INT(id_); | |
1384 | + commands::CompositionMode mode; | |
1385 | + commands::SessionCommand command; | |
1386 | + | |
1387 | + switch (C_INT(new_mode_)) { | |
1388 | + case -1: | |
1389 | + mode = commands::DIRECT; | |
1390 | + break; | |
1391 | + case 0: | |
1392 | + mode = commands::HIRAGANA; | |
1393 | + break; | |
1394 | + case 1: | |
1395 | + mode = commands::FULL_KATAKANA; | |
1396 | + break; | |
1397 | + case 2: | |
1398 | + mode = commands::HALF_KATAKANA; | |
1399 | + break; | |
1400 | + case 3: | |
1401 | + mode = commands::HALF_ASCII; | |
1402 | + break; | |
1403 | + case 4: | |
1404 | + mode = commands::FULL_ASCII; | |
1405 | + break; | |
1406 | + default: | |
1407 | + mode = commands::HIRAGANA; | |
1408 | + break; | |
1409 | + } | |
1410 | + | |
1411 | + if (mode == commands::DIRECT) { | |
1412 | + command.set_type(commands::SessionCommand::SUBMIT); | |
1413 | + context_slot[id].session->SendCommand(command, context_slot[id].output); | |
1414 | + update_all(mc_, id); | |
1415 | + uim_scm_callf("mozc-context-set-on!", "oo", mc_, uim_scm_f()); | |
1416 | + } else { | |
1417 | + command.set_type(commands::SessionCommand::SWITCH_INPUT_MODE); | |
1418 | + command.set_composition_mode(mode); | |
1419 | + context_slot[id].session->SendCommand(command, context_slot[id].output); | |
1420 | + context_slot[id].currentMode = mode; /* don't set this with DIRECT mode */ | |
1421 | + uim_scm_callf("mozc-context-set-on!", "oo", mc_, uim_scm_t()); | |
1422 | + } | |
1423 | + | |
1424 | + return uim_scm_t(); | |
1425 | +} | |
1426 | + | |
1427 | +static uim_lisp | |
1428 | +set_composition_on(uim_lisp id_) | |
1429 | +{ | |
1430 | + int id = C_INT(id_); | |
1431 | + commands::SessionCommand command; | |
1432 | + | |
1433 | + command.set_type(commands::SessionCommand::SWITCH_INPUT_MODE); | |
1434 | + command.set_composition_mode(context_slot[id].currentMode); | |
1435 | + context_slot[id].session->SendCommand(command, context_slot[id].output); | |
1436 | + | |
1437 | + return uim_scm_t(); | |
1438 | +} | |
1439 | + | |
1440 | +static uim_lisp | |
1441 | +has_preedit(uim_lisp id_) | |
1442 | +{ | |
1443 | + int id = C_INT(id_); | |
1444 | + | |
1445 | + return context_slot[id].has_preedit_before ? uim_scm_t() : uim_scm_f(); | |
1446 | +} | |
1447 | + | |
1448 | +static uim_lisp | |
1449 | +select_candidate(uim_lisp mc_, uim_lisp id_, uim_lisp idx_) | |
1450 | +{ | |
1451 | + int id = C_INT(id_); | |
1452 | + int idx = C_INT(idx_) % 9; | |
1453 | + | |
1454 | +#if USE_CASCADING_CANDIDATES | |
1455 | + if (idx >= context_slot[id].unique_candidate_ids->size()) | |
1456 | +#else | |
1457 | + if (idx >= context_slot[id].output->candidates().candidate_size()) | |
1458 | +#endif | |
1459 | + return uim_scm_f(); | |
1460 | + | |
1461 | +#if USE_CASCADING_CANDIDATES | |
1462 | + const int32 cand_id = (*context_slot[id].unique_candidate_ids)[idx]; | |
1463 | + if (cand_id == kBadCandidateId) | |
1464 | + return uim_scm_f(); | |
1465 | +#else | |
1466 | + const int32 cand_id = context_slot[id].output->candidates().candidate(idx).id(); | |
1467 | +#endif | |
1468 | + | |
1469 | + commands::Output output; | |
1470 | + commands::SessionCommand command; | |
1471 | + command.set_type(commands::SessionCommand::SELECT_CANDIDATE); | |
1472 | + command.set_id(cand_id); | |
1473 | + context_slot[id].session->SendCommand(command, context_slot[id].output); | |
1474 | + update_all(mc_, id); | |
1475 | + | |
1476 | + return uim_scm_t(); | |
1477 | +} | |
1478 | + | |
1479 | +static uim_lisp | |
1480 | +get_input_rule(uim_lisp id_) | |
1481 | +{ | |
1482 | + int id = C_INT(id_); | |
1483 | + const config::Config::PreeditMethod method = context_slot[id].preedit_method; | |
1484 | + int rule = 0; | |
1485 | + | |
1486 | + switch (method) { | |
1487 | + case config::Config::ROMAN: | |
1488 | + rule = 0; | |
1489 | + break; | |
1490 | + case config::Config::KANA: | |
1491 | + rule = 1; | |
1492 | + break; | |
1493 | + default: | |
1494 | + rule = 0; | |
1495 | + break; | |
1496 | + } | |
1497 | + | |
1498 | + return MAKE_INT(rule); | |
1499 | +} | |
1500 | + | |
1501 | +static uim_lisp | |
1502 | +set_input_rule(uim_lisp mc_, uim_lisp id_, uim_lisp new_rule_) | |
1503 | +{ | |
1504 | + int id = C_INT(id_); | |
1505 | + config::Config config; | |
1506 | + config::Config::PreeditMethod method; | |
1507 | + | |
1508 | + switch (C_INT(new_rule_)) { | |
1509 | + case 0: | |
1510 | + method = config::Config::ROMAN; | |
1511 | + break; | |
1512 | + case 1: | |
1513 | + method = config::Config::KANA; | |
1514 | + break; | |
1515 | + default: | |
1516 | + method = config::Config::ROMAN; | |
1517 | + break; | |
1518 | + } | |
1519 | + | |
1520 | + if (!context_slot[id].session->GetConfig(&config)) | |
1521 | + return false; | |
1522 | + | |
1523 | + config.set_preedit_method(method); | |
1524 | + | |
1525 | + if (!context_slot[id].session->SetConfig(config)) | |
1526 | + return false; | |
1527 | + | |
1528 | + context_slot[id].preedit_method = method; | |
1529 | + | |
1530 | + return uim_scm_t(); | |
1531 | +} | |
1532 | + | |
1533 | +} // namespace | |
1534 | +} // namespace | |
1535 | + | |
1536 | + | |
1537 | + | |
1538 | +void | |
1539 | +uim_plugin_instance_init(void) | |
1540 | +{ | |
1541 | + uim_scm_init_proc1("mozc-lib-alloc-context", mozc::uim::create_context); | |
1542 | + uim_scm_init_proc1("mozc-lib-free-context", mozc::uim::release_context); | |
1543 | + uim_scm_init_proc1("mozc-lib-reset", mozc::uim::reset_context); | |
1544 | + uim_scm_init_proc4("mozc-lib-press-key", mozc::uim::press_key); | |
1545 | + uim_scm_init_proc3("mozc-lib-release-key", mozc::uim::release_key); | |
1546 | + uim_scm_init_proc1("mozc-lib-get-nr-candidates", mozc::uim::get_nr_candidates); | |
1547 | + uim_scm_init_proc2("mozc-lib-get-nth-candidate", mozc::uim::get_nth_candidate); | |
1548 | + uim_scm_init_proc2("mozc-lib-get-nth-label", mozc::uim::get_nth_label); | |
1549 | + uim_scm_init_proc2("mozc-lib-get-nth-annotation", mozc::uim::get_nth_annotation); | |
1550 | + uim_scm_init_proc1("keysym-to-int", mozc::uim::keysym_to_int); | |
1551 | + uim_scm_init_proc1("mozc-lib-input-mode", mozc::uim::get_composition_mode); | |
1552 | + uim_scm_init_proc3("mozc-lib-set-input-mode", mozc::uim::set_composition_mode); | |
1553 | + uim_scm_init_proc1("mozc-lib-set-on", mozc::uim::set_composition_on); | |
1554 | + uim_scm_init_proc1("mozc-lib-has-preedit?", mozc::uim::has_preedit); | |
1555 | + uim_scm_init_proc3("mozc-lib-set-candidate-index", mozc::uim::select_candidate); | |
1556 | + uim_scm_init_proc1("mozc-lib-input-rule", mozc::uim::get_input_rule); | |
1557 | + uim_scm_init_proc3("mozc-lib-set-input-rule", mozc::uim::set_input_rule); | |
1558 | + | |
1559 | + int argc = 1; | |
1560 | + static const char name[] = "uim-mozc"; | |
1561 | + argv = (char **)malloc(sizeof(char *) * 2); | |
1562 | + argv[0] = (char *)name; | |
1563 | + argv[1] = NULL; | |
1564 | + | |
1565 | + InitGoogle((const char *)argv[0], &argc, (char ***)&argv, true); | |
1566 | + mozc::uim::install_keymap(); | |
1567 | +} | |
1568 | + | |
1569 | +void | |
1570 | +uim_plugin_instance_quit(void) | |
1571 | +{ | |
1572 | + mozc::uim::key_map.clear(); | |
1573 | + for (int i = 0; i < mozc::uim::nr_contexts; i++) { | |
1574 | + if (mozc::uim::context_slot[i].session) { | |
1575 | + delete mozc::uim::context_slot[i].session; | |
1576 | + delete mozc::uim::context_slot[i].keyTranslator; | |
1577 | + delete mozc::uim::context_slot[i].output; | |
1578 | + } | |
1579 | + } | |
1580 | + free(argv); | |
1581 | +} | |
1582 | diff --git a/unix/uim/scm/mozc-custom.scm b/unix/uim/scm/mozc-custom.scm | |
1583 | new file mode 100644 | |
1584 | index 0000000..d2cea8c | |
1585 | --- /dev/null | |
1586 | +++ b/unix/uim/scm/mozc-custom.scm | |
1587 | @@ -0,0 +1,259 @@ | |
1588 | +;;; | |
1589 | +;;; Copyright (c) 2010 uim Project http://code.google.com/p/uim/ | |
1590 | +;;; | |
1591 | +;;; All rights reserved. | |
1592 | +;;; | |
1593 | +;;; Redistribution and use in source and binary forms, with or without | |
1594 | +;;; modification, are permitted provided that the following conditions | |
1595 | +;;; are met: | |
1596 | +;;; 1. Redistributions of source code must retain the above copyright | |
1597 | +;;; notice, this list of conditions and the following disclaimer. | |
1598 | +;;; 2. Redistributions in binary form must reproduce the above copyright | |
1599 | +;;; notice, this list of conditions and the following disclaimer in the | |
1600 | +;;; documentation and/or other materials provided with the distribution. | |
1601 | +;;; 3. Neither the name of authors nor the names of its contributors | |
1602 | +;;; may be used to endorse or promote products derived from this software | |
1603 | +;;; without specific prior written permission. | |
1604 | +;;; | |
1605 | +;;; THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS ``AS IS'' AND | |
1606 | +;;; ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE | |
1607 | +;;; IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE | |
1608 | +;;; ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDERS OR CONTRIBUTORS BE LIABLE | |
1609 | +;;; FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL | |
1610 | +;;; DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS | |
1611 | +;;; OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) | |
1612 | +;;; HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT | |
1613 | +;;; LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY | |
1614 | +;;; OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF | |
1615 | +;;; SUCH DAMAGE. | |
1616 | +;;;; | |
1617 | + | |
1618 | +(require "i18n.scm") | |
1619 | + | |
1620 | +(define mozc-im-name-label (N_ "Mozc")) | |
1621 | +(define mozc-im-short-desc (N_ "Mozc Japanese engine")) | |
1622 | + | |
1623 | +(define-custom-group 'mozc | |
1624 | + (ugettext mozc-im-name-label) | |
1625 | + (ugettext mozc-im-short-desc)) | |
1626 | + | |
1627 | +;; | |
1628 | +;; segment separator | |
1629 | +;; | |
1630 | + | |
1631 | +(define-custom 'mozc-show-segment-separator? #f | |
1632 | + '(mozc segment-sep) | |
1633 | + '(boolean) | |
1634 | + (N_ "Show segment separator") | |
1635 | + (N_ "long description will be here.")) | |
1636 | + | |
1637 | +(define-custom 'mozc-segment-separator "|" | |
1638 | + '(mozc segment-sep) | |
1639 | + '(string ".*") | |
1640 | + (N_ "Segment separator") | |
1641 | + (N_ "long description will be here.")) | |
1642 | + | |
1643 | +(custom-add-hook 'mozc-segment-separator | |
1644 | + 'custom-activity-hooks | |
1645 | + (lambda () | |
1646 | + mozc-show-segment-separator?)) | |
1647 | + | |
1648 | +;; | |
1649 | +;; toolbar | |
1650 | +;; | |
1651 | + | |
1652 | +;; Can't be unified with action definitions in mozc.scm until uim | |
1653 | +;; 0.4.6. | |
1654 | +(define mozc-input-mode-indication-alist | |
1655 | + (list | |
1656 | + (list 'action_mozc_direct | |
1657 | + 'ja_direct | |
1658 | + "-" | |
1659 | + (N_ "Direct input") | |
1660 | + (N_ "Direct input mode")) | |
1661 | + (list 'action_mozc_hiragana | |
1662 | + 'ja_hiragana | |
1663 | + "あ" | |
1664 | + (N_ "Hiragana") | |
1665 | + (N_ "Hiragana input mode")) | |
1666 | + (list 'action_mozc_katakana | |
1667 | + 'ja_katakana | |
1668 | + "ア" | |
1669 | + (N_ "Katakana") | |
1670 | + (N_ "Katakana input mode")) | |
1671 | + (list 'action_mozc_halfkana | |
1672 | + 'ja_halfkana | |
1673 | + "ア" | |
1674 | + (N_ "Halfwidth Katakana") | |
1675 | + (N_ "Halfwidth Katakana input mode")) | |
1676 | + (list 'action_mozc_halfwidth_alnum | |
1677 | + 'ja_halfwidth_alnum | |
1678 | + "a" | |
1679 | + (N_ "Halfwidth Alphanumeric") | |
1680 | + (N_ "Halfwidth Alphanumeric input mode")) | |
1681 | + (list 'action_mozc_fullwidth_alnum | |
1682 | + 'ja_fullwidth_alnum | |
1683 | + "A" | |
1684 | + (N_ "Fullwidth Alphanumeric") | |
1685 | + (N_ "Fullwidth Alphanumeric input mode")))) | |
1686 | + | |
1687 | +(define mozc-kana-input-method-indication-alist | |
1688 | + (list | |
1689 | + (list 'action_mozc_roma | |
1690 | + 'ja_romaji | |
1691 | + "R" | |
1692 | + (N_ "Romaji") | |
1693 | + (N_ "Romaji input mode")) | |
1694 | + (list 'action_mozc_kana | |
1695 | + 'ja_kana | |
1696 | + "か" | |
1697 | + (N_ "Kana") | |
1698 | + (N_ "Kana input mode")))) | |
1699 | + | |
1700 | +;;; Buttons | |
1701 | + | |
1702 | +(define-custom 'mozc-widgets '(widget_mozc_input_mode | |
1703 | + widget_mozc_kana_input_method) | |
1704 | + '(mozc toolbar) | |
1705 | + (list 'ordered-list | |
1706 | + (list 'widget_mozc_input_mode | |
1707 | + (_ "Input mode") | |
1708 | + (_ "Input mode")) | |
1709 | + (list 'widget_mozc_kana_input_method | |
1710 | + (_ "Kana input method") | |
1711 | + (_ "Kana input method"))) | |
1712 | + (_ "Enabled toolbar buttons") | |
1713 | + (_ "long description will be here.")) | |
1714 | + | |
1715 | +;; dynamic reconfiguration | |
1716 | +;; mozc-configure-widgets is not defined at this point. So wrapping | |
1717 | +;; into lambda. | |
1718 | +(custom-add-hook 'mozc-widgets | |
1719 | + 'custom-set-hooks | |
1720 | + (lambda () | |
1721 | + (mozc-configure-widgets))) | |
1722 | + | |
1723 | + | |
1724 | +;;; Input mode | |
1725 | + | |
1726 | +(define-custom 'default-widget_mozc_input_mode 'action_mozc_direct | |
1727 | + '(mozc toolbar) | |
1728 | + (cons 'choice | |
1729 | + (map indication-alist-entry-extract-choice | |
1730 | + mozc-input-mode-indication-alist)) | |
1731 | + (_ "Default input mode") | |
1732 | + (_ "long description will be here.")) | |
1733 | + | |
1734 | +(define-custom 'mozc-input-mode-actions | |
1735 | + (map car mozc-input-mode-indication-alist) | |
1736 | + '(mozc toolbar) | |
1737 | + (cons 'ordered-list | |
1738 | + (map indication-alist-entry-extract-choice | |
1739 | + mozc-input-mode-indication-alist)) | |
1740 | + (_ "Input mode menu items") | |
1741 | + (_ "long description will be here.")) | |
1742 | + | |
1743 | +;; value dependency | |
1744 | +(if custom-full-featured? | |
1745 | + (custom-add-hook 'mozc-input-mode-actions | |
1746 | + 'custom-set-hooks | |
1747 | + (lambda () | |
1748 | + (custom-choice-range-reflect-olist-val | |
1749 | + 'default-widget_mozc_input_mode | |
1750 | + 'mozc-input-mode-actions | |
1751 | + mozc-input-mode-indication-alist)))) | |
1752 | + | |
1753 | +;; activity dependency | |
1754 | +(custom-add-hook 'default-widget_mozc_input_mode | |
1755 | + 'custom-activity-hooks | |
1756 | + (lambda () | |
1757 | + (memq 'widget_mozc_input_mode mozc-widgets))) | |
1758 | + | |
1759 | +(custom-add-hook 'mozc-input-mode-actions | |
1760 | + 'custom-activity-hooks | |
1761 | + (lambda () | |
1762 | + (memq 'widget_mozc_input_mode mozc-widgets))) | |
1763 | + | |
1764 | +;; dynamic reconfiguration | |
1765 | +(custom-add-hook 'default-widget_mozc_input_mode | |
1766 | + 'custom-set-hooks | |
1767 | + (lambda () | |
1768 | + (mozc-configure-widgets))) | |
1769 | + | |
1770 | +(custom-add-hook 'mozc-input-mode-actions | |
1771 | + 'custom-set-hooks | |
1772 | + (lambda () | |
1773 | + (mozc-configure-widgets))) | |
1774 | + | |
1775 | +;;; Kana input method | |
1776 | + | |
1777 | +(define-custom 'default-widget_mozc_kana_input_method 'action_mozc_roma | |
1778 | + '(mozc toolbar) | |
1779 | + (cons 'choice | |
1780 | + (map indication-alist-entry-extract-choice | |
1781 | + mozc-kana-input-method-indication-alist)) | |
1782 | + (N_ "Default kana input method") | |
1783 | + (N_ "long description will be here.")) | |
1784 | + | |
1785 | +(define-custom 'mozc-kana-input-method-actions | |
1786 | + (map car mozc-kana-input-method-indication-alist) | |
1787 | + '(mozc toolbar) | |
1788 | + (cons 'ordered-list | |
1789 | + (map indication-alist-entry-extract-choice | |
1790 | + mozc-kana-input-method-indication-alist)) | |
1791 | + (N_ "Kana input method menu items") | |
1792 | + (N_ "long description will be here.")) | |
1793 | + | |
1794 | +;; value dependency | |
1795 | +(if custom-full-featured? | |
1796 | + (custom-add-hook 'mozc-kana-input-method-actions | |
1797 | + 'custom-set-hooks | |
1798 | + (lambda () | |
1799 | + (custom-choice-range-reflect-olist-val | |
1800 | + 'default-widget_mozc_kana_input_method | |
1801 | + 'mozc-kana-input-method-actions | |
1802 | + mozc-kana-input-method-indication-alist)))) | |
1803 | + | |
1804 | +;; activity dependency | |
1805 | +(custom-add-hook 'default-widget_mozc_kana_input_method | |
1806 | + 'custom-activity-hooks | |
1807 | + (lambda () | |
1808 | + (memq 'widget_mozc_kana_input_method mozc-widgets | |
1809 | +))) | |
1810 | + | |
1811 | +(custom-add-hook 'mozc-kana-input-method-actions | |
1812 | + 'custom-activity-hooks | |
1813 | + (lambda () | |
1814 | + (memq 'widget_mozc_kana_input_method mozc-widgets | |
1815 | +))) | |
1816 | + | |
1817 | +;; dynamic reconfiguration | |
1818 | +(custom-add-hook 'default-widget_mozc_kana_input_method | |
1819 | + 'custom-set-hooks | |
1820 | + (lambda () | |
1821 | + (mozc-configure-widgets))) | |
1822 | + | |
1823 | +(custom-add-hook 'mozc-kana-input-method-actions | |
1824 | + 'custom-set-hooks | |
1825 | + (lambda () | |
1826 | + (mozc-configure-widgets))) | |
1827 | + | |
1828 | + | |
1829 | +(define-custom 'mozc-use-with-vi? #f | |
1830 | + '(mozc special-op) | |
1831 | + '(boolean) | |
1832 | + (N_ "Enable vi-cooperative mode") | |
1833 | + (N_ "long description will be here.")) | |
1834 | + | |
1835 | +(define-custom 'mozc-keyboard-type-for-kana-input-method 'jp-keyboard | |
1836 | + '(mozc) | |
1837 | + (list 'choice | |
1838 | + (list 'jp-keyboard | |
1839 | + (N_ "Japanese keyboard") | |
1840 | + (N_ "long description will be here.")) | |
1841 | + (list 'us-keyboard | |
1842 | + (N_ "US keyboard") | |
1843 | + (N_ "long description will be here."))) | |
1844 | + (N_ "Keyboard type for kana input method") | |
1845 | + (N_ "long description will be here.")) | |
1846 | + | |
1847 | diff --git a/unix/uim/scm/mozc-key-custom.scm b/unix/uim/scm/mozc-key-custom.scm | |
1848 | new file mode 100644 | |
1849 | index 0000000..553fe1f | |
1850 | --- /dev/null | |
1851 | +++ b/unix/uim/scm/mozc-key-custom.scm | |
1852 | @@ -0,0 +1,74 @@ | |
1853 | +;;; | |
1854 | +;;; Copyright (c) 2010 uim Project http://code.google.com/p/uim/ | |
1855 | +;;; | |
1856 | +;;; All rights reserved. | |
1857 | +;;; | |
1858 | +;;; Redistribution and use in source and binary forms, with or without | |
1859 | +;;; modification, are permitted provided that the following conditions | |
1860 | +;;; are met: | |
1861 | +;;; 1. Redistributions of source code must retain the above copyright | |
1862 | +;;; notice, this list of conditions and the following disclaimer. | |
1863 | +;;; 2. Redistributions in binary form must reproduce the above copyright | |
1864 | +;;; notice, this list of conditions and the following disclaimer in the | |
1865 | +;;; documentation and/or other materials provided with the distribution. | |
1866 | +;;; 3. Neither the name of authors nor the names of its contributors | |
1867 | +;;; may be used to endorse or promote products derived from this software | |
1868 | +;;; without specific prior written permission. | |
1869 | +;;; | |
1870 | +;;; THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS ``AS IS'' AND | |
1871 | +;;; ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE | |
1872 | +;;; IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE | |
1873 | +;;; ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDERS OR CONTRIBUTORS BE LIABLE | |
1874 | +;;; FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL | |
1875 | +;;; DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS | |
1876 | +;;; OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) | |
1877 | +;;; HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT | |
1878 | +;;; LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY | |
1879 | +;;; OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF | |
1880 | +;;; SUCH DAMAGE. | |
1881 | +;;;; | |
1882 | + | |
1883 | +(require "i18n.scm") | |
1884 | + | |
1885 | +(define-custom-group 'mozc-keys | |
1886 | + (_ "Mozc key bindings") | |
1887 | + (_ "long description will be here.")) | |
1888 | + | |
1889 | +;; | |
1890 | +;; overriding generic keys | |
1891 | +;; | |
1892 | +(define-custom 'mozc-on-key '(generic-on-key) | |
1893 | + '(mozc-keys) | |
1894 | + '(key) | |
1895 | + (_ "[Mozc] on") | |
1896 | + (_ "long description will be here")) | |
1897 | + | |
1898 | +(define-custom 'mozc-off-key '(generic-off-key) | |
1899 | + '(mozc-keys) | |
1900 | + '(key) | |
1901 | + (_ "[Mozc] off") | |
1902 | + (_ "long description will be here")) | |
1903 | + | |
1904 | +(define-custom 'mozc-kana-toggle-key '() | |
1905 | + '(mozc-keys) | |
1906 | + '(key) | |
1907 | + (_ "[Mozc] toggle hiragana/katakana mode") | |
1908 | + (_ "long description will be here")) | |
1909 | + | |
1910 | +;;(define-custom 'mozc-cancel-key '(generic-cancel-key) | |
1911 | +;; '(mozc-keys) | |
1912 | +;; '(key) | |
1913 | +;; (_ "[Mozc] cancel") | |
1914 | +;; (_ "long description will be here")) | |
1915 | +;; | |
1916 | +;;(define-custom 'mozc-prev-segment-key '(generic-go-left-key) | |
1917 | +;; '(mozc-keys) | |
1918 | +;; '(key) | |
1919 | +;; (_ "[Mozc] previous segment") | |
1920 | +;; (_ "long description will be here")) | |
1921 | + | |
1922 | +(define-custom 'mozc-vi-escape-key '("escape" "<Control>[") | |
1923 | + '(mozc-keys) | |
1924 | + '(key) | |
1925 | + (_ "[Mozc] ESC keys on vi-cooperative mode") | |
1926 | + (_ "long description will be here")) | |
1927 | diff --git a/unix/uim/scm/mozc.scm b/unix/uim/scm/mozc.scm | |
1928 | new file mode 100644 | |
1929 | index 0000000..4aa0417 | |
1930 | --- /dev/null | |
1931 | +++ b/unix/uim/scm/mozc.scm | |
1932 | @@ -0,0 +1,350 @@ | |
1933 | +;;; | |
1934 | +;;; Copyright (c) 2010 uim Project http://code.google.com/p/uim/ | |
1935 | +;;; | |
1936 | +;;; All rights reserved. | |
1937 | +;;; | |
1938 | +;;; Redistribution and use in source and binary forms, with or without | |
1939 | +;;; modification, are permitted provided that the following conditions | |
1940 | +;;; are met: | |
1941 | +;;; 1. Redistributions of source code must retain the above copyright | |
1942 | +;;; notice, this list of conditions and the following disclaimer. | |
1943 | +;;; 2. Redistributions in binary form must reproduce the above copyright | |
1944 | +;;; notice, this list of conditions and the following disclaimer in the | |
1945 | +;;; documentation and/or other materials provided with the distribution. | |
1946 | +;;; 3. Neither the name of authors nor the names of its contributors | |
1947 | +;;; may be used to endorse or promote products derived from this software | |
1948 | +;;; without specific prior written permission. | |
1949 | +;;; | |
1950 | +;;; THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS ``AS IS'' AND | |
1951 | +;;; ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE | |
1952 | +;;; IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE | |
1953 | +;;; ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDERS OR CONTRIBUTORS BE LIABLE | |
1954 | +;;; FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL | |
1955 | +;;; DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS | |
1956 | +;;; OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) | |
1957 | +;;; HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT | |
1958 | +;;; LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY | |
1959 | +;;; OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF | |
1960 | +;;; SUCH DAMAGE. | |
1961 | +;;;; | |
1962 | + | |
1963 | +(require "util.scm") | |
1964 | +(require "japanese.scm") | |
1965 | +(require-custom "generic-key-custom.scm") | |
1966 | +(require-custom "mozc-custom.scm") | |
1967 | +(require-custom "mozc-key-custom.scm") | |
1968 | + | |
1969 | +;;; implementations | |
1970 | + | |
1971 | +(define mozc-type-direct ja-type-direct) | |
1972 | +(define mozc-type-hiragana ja-type-hiragana) | |
1973 | +(define mozc-type-katakana ja-type-katakana) | |
1974 | +(define mozc-type-halfkana ja-type-halfkana) | |
1975 | +(define mozc-type-halfwidth-alnum ja-type-halfwidth-alnum) | |
1976 | +(define mozc-type-fullwidth-alnum ja-type-fullwidth-alnum) | |
1977 | + | |
1978 | +(define mozc-input-rule-roma 0) | |
1979 | +(define mozc-input-rule-kana 1) | |
1980 | + | |
1981 | +(define mozc-prepare-input-mode-activation | |
1982 | + (lambda (mc new-mode) | |
1983 | + (mozc-lib-set-input-mode mc (mozc-context-mc-id mc) new-mode))) | |
1984 | + | |
1985 | +(define mozc-prepare-input-rule-activation | |
1986 | + (lambda (mc new-rule) | |
1987 | + (mozc-lib-set-input-rule mc (mozc-context-mc-id mc) new-rule))) | |
1988 | + | |
1989 | +(register-action 'action_mozc_hiragana | |
1990 | + (lambda (mc) ;; indication handler | |
1991 | + '(ja_hiragana | |
1992 | + "あ" | |
1993 | + "ひらがな" | |
1994 | + "ひらがな入力モード")) | |
1995 | + (lambda (mc) ;; activity predicate | |
1996 | + (and | |
1997 | + (mozc-context-on mc) | |
1998 | + (= (mozc-lib-input-mode (mozc-context-mc-id mc)) mozc-type-hiragana))) | |
1999 | + (lambda (mc) ;; action handler | |
2000 | + (mozc-prepare-input-mode-activation mc mozc-type-hiragana))) | |
2001 | + | |
2002 | +(register-action 'action_mozc_katakana | |
2003 | + (lambda (mc) | |
2004 | + '(ja_katakana | |
2005 | + "ア" | |
2006 | + "カタカナ" | |
2007 | + "カタカナ入力モード")) | |
2008 | + (lambda (mc) | |
2009 | + (and | |
2010 | + (mozc-context-on mc) | |
2011 | + (= (mozc-lib-input-mode (mozc-context-mc-id mc)) mozc-type-katakana))) | |
2012 | + (lambda (mc) | |
2013 | + (mozc-prepare-input-mode-activation mc mozc-type-katakana))) | |
2014 | + | |
2015 | +(register-action 'action_mozc_halfkana | |
2016 | + (lambda (mc) | |
2017 | + '(ja_halfkana | |
2018 | + "ア" | |
2019 | + "半角カタカナ" | |
2020 | + "半角カタカナ入力モード")) | |
2021 | + (lambda (mc) | |
2022 | + (and | |
2023 | + (mozc-context-on mc) | |
2024 | + (= (mozc-lib-input-mode (mozc-context-mc-id mc)) mozc-type-halfkana))) | |
2025 | + (lambda (mc) | |
2026 | + (mozc-prepare-input-mode-activation mc mozc-type-halfkana))) | |
2027 | + | |
2028 | +(register-action 'action_mozc_halfwidth_alnum | |
2029 | + (lambda (mc) | |
2030 | + '(ja_halfwidth_alnum | |
2031 | + "a" | |
2032 | + "半角英数" | |
2033 | + "半角英数入力モード")) | |
2034 | + (lambda (mc) | |
2035 | + (and | |
2036 | + (mozc-context-on mc) | |
2037 | + (= (mozc-lib-input-mode (mozc-context-mc-id mc)) mozc-type-halfwidth-alnum))) | |
2038 | + (lambda (mc) | |
2039 | + (mozc-prepare-input-mode-activation mc mozc-type-halfwidth-alnum))) | |
2040 | + | |
2041 | +(register-action 'action_mozc_direct | |
2042 | + (lambda (mc) | |
2043 | + '(ja_direct | |
2044 | + "-" | |
2045 | + "直接入力" | |
2046 | + "直接(無変換)入力モード")) | |
2047 | + (lambda (mc) | |
2048 | + (not (mozc-context-on mc))) | |
2049 | + (lambda (mc) | |
2050 | + (mozc-prepare-input-mode-activation mc mozc-type-direct))) | |
2051 | + | |
2052 | +(register-action 'action_mozc_fullwidth_alnum | |
2053 | + (lambda (mc) | |
2054 | + '(ja_fullwidth_alnum | |
2055 | + "A" | |
2056 | + "全角英数" | |
2057 | + "全角英数入力モード")) | |
2058 | + (lambda (mc) | |
2059 | + (and | |
2060 | + (mozc-context-on mc) | |
2061 | + (= (mozc-lib-input-mode (mozc-context-mc-id mc)) mozc-type-fullwidth-alnum))) | |
2062 | + (lambda (mc) | |
2063 | + (mozc-prepare-input-mode-activation mc mozc-type-fullwidth-alnum))) | |
2064 | + | |
2065 | +(register-action 'action_mozc_roma | |
2066 | +;; (indication-alist-indicator 'action_mozc_roma | |
2067 | +;; mozc-kana-input-method-indication-alist) | |
2068 | + (lambda (mc) | |
2069 | + '(ja_romaji | |
2070 | + "R" | |
2071 | + "ローマ字" | |
2072 | + "ローマ字入力モード")) | |
2073 | + (lambda (mc) | |
2074 | + (= (mozc-lib-input-rule (mozc-context-mc-id mc)) | |
2075 | + mozc-input-rule-roma)) | |
2076 | + (lambda (mc) | |
2077 | + (mozc-prepare-input-rule-activation mc mozc-input-rule-roma) | |
2078 | +)) | |
2079 | + | |
2080 | +(register-action 'action_mozc_kana | |
2081 | +;; (indication-alist-indicator 'action_mozc_kana | |
2082 | +;; mozc-kana-input-method-indication-alist) | |
2083 | + (lambda (mc) | |
2084 | + '(ja_kana | |
2085 | + "か" | |
2086 | + "かな" | |
2087 | + "かな入力モード")) | |
2088 | + (lambda (mc) | |
2089 | + (= (mozc-lib-input-rule (mozc-context-mc-id mc)) | |
2090 | + mozc-input-rule-kana)) | |
2091 | + (lambda (mc) | |
2092 | + (mozc-prepare-input-rule-activation mc mozc-input-rule-kana) | |
2093 | + )) | |
2094 | + | |
2095 | +;; Update widget definitions based on action configurations. The | |
2096 | +;; procedure is needed for on-the-fly reconfiguration involving the | |
2097 | +;; custom API | |
2098 | +(define mozc-configure-widgets | |
2099 | + (lambda () | |
2100 | + (register-widget 'widget_mozc_input_mode | |
2101 | + (activity-indicator-new mozc-input-mode-actions) | |
2102 | + (actions-new mozc-input-mode-actions)) | |
2103 | + (register-widget 'widget_mozc_kana_input_method | |
2104 | + (activity-indicator-new mozc-kana-input-method-actions) | |
2105 | + (actions-new mozc-kana-input-method-actions)) | |
2106 | + (context-list-replace-widgets! 'mozc mozc-widgets))) | |
2107 | + | |
2108 | +(define mozc-context-rec-spec | |
2109 | + (append | |
2110 | + context-rec-spec | |
2111 | + ;; renamed from 'id' to avoid conflict with context-id | |
2112 | + (list | |
2113 | + (list 'mc-id #f) | |
2114 | + (list 'on #f)))) | |
2115 | +(define-record 'mozc-context mozc-context-rec-spec) | |
2116 | +(define mozc-context-new-internal mozc-context-new) | |
2117 | + | |
2118 | +(define mozc-context-new | |
2119 | + (lambda (id im name) | |
2120 | + (let* ((mc (mozc-context-new-internal id im)) | |
2121 | + (mc-id (mozc-lib-alloc-context mc))) | |
2122 | + (mozc-context-set-widgets! mc mozc-widgets) | |
2123 | + (mozc-context-set-mc-id! mc mc-id) | |
2124 | + mc))) | |
2125 | + | |
2126 | +(define mozc-separator | |
2127 | + (lambda () | |
2128 | + (let ((attr (bitwise-ior preedit-separator | |
2129 | + preedit-underline))) | |
2130 | + (if mozc-show-segment-separator? | |
2131 | + (cons attr mozc-segment-separator) | |
2132 | + #f)))) | |
2133 | + | |
2134 | +(define mozc-proc-direct-state | |
2135 | + (lambda (mc key key-state) | |
2136 | + (if (mozc-on-key? key key-state) | |
2137 | + (begin | |
2138 | + (mozc-lib-set-on (mozc-context-mc-id mc)) | |
2139 | + (mozc-context-set-on! mc #t)) | |
2140 | + (im-commit-raw mc)))) | |
2141 | + | |
2142 | +(define mozc-init-handler | |
2143 | + (lambda (id im arg) | |
2144 | + (mozc-context-new id im arg))) | |
2145 | + | |
2146 | +(define mozc-release-handler | |
2147 | + (lambda (mc) | |
2148 | + (let ((mc-id (mozc-context-mc-id mc))) | |
2149 | + (if mc-id | |
2150 | + (mozc-lib-free-context mc-id) | |
2151 | + #f) | |
2152 | + #f))) | |
2153 | + | |
2154 | +(define mozc-transpose-keys | |
2155 | + (lambda (mid key key-state) | |
2156 | + (let ((new (cons key key-state))) | |
2157 | + ;; Since mozc_tool is now available, these key transposings | |
2158 | + ;; are not needed usually. | |
2159 | + ;;(if (mozc-lib-has-preedit? mid) | |
2160 | + ;; (cond | |
2161 | + ;; ((mozc-cancel-key? key key-state) | |
2162 | + ;; (set-car! new 'escape) | |
2163 | + ;; (set-cdr! new 0)) | |
2164 | + ;; ((mozc-prev-segment-key? key key-state) | |
2165 | + ;; (set-car! new 'left) | |
2166 | + ;; (set-cdr! new 0)))) | |
2167 | + new))) | |
2168 | + | |
2169 | +(define mozc-kana-toggle | |
2170 | + (lambda (mc mid) | |
2171 | + (let ((mode (mozc-lib-input-mode mid))) | |
2172 | + (cond | |
2173 | + ((= mode mozc-type-hiragana) | |
2174 | + (mozc-lib-set-input-mode mc mid mozc-type-katakana)) | |
2175 | + ((= mode mozc-type-katakana) | |
2176 | + (mozc-lib-set-input-mode mc mid mozc-type-hiragana)) | |
2177 | + (else | |
2178 | + #f))))) | |
2179 | + | |
2180 | +(define mozc-proc-input-state | |
2181 | + (lambda (mc key key-state) | |
2182 | + (if (ichar-control? key) | |
2183 | + (im-commit-raw mc) | |
2184 | + (let ((mid (mozc-context-mc-id mc))) | |
2185 | + (cond | |
2186 | + ((mozc-off-key? key key-state) | |
2187 | + (mozc-lib-set-input-mode mc mid mozc-type-direct)) | |
2188 | + ;; non available modifiers on Mozc | |
2189 | + ((or | |
2190 | + (meta-key-mask key-state) | |
2191 | + (super-key-mask key-state) | |
2192 | + (hyper-key-mask key-state)) | |
2193 | + (if (mozc-lib-has-preedit? mid) | |
2194 | + #f ;; ignore | |
2195 | + (im-commit-raw mc))) ;; pass through | |
2196 | + (else | |
2197 | + (or | |
2198 | + (and | |
2199 | + (mozc-kana-toggle-key? key key-state) | |
2200 | + (mozc-kana-toggle mc mid)) | |
2201 | + (let* ((new (mozc-transpose-keys mid key key-state)) | |
2202 | + (nkey (car new)) | |
2203 | + (nkey-state (cdr new))) | |
2204 | + (if (mozc-lib-press-key mc mid (if (symbol? nkey) | |
2205 | + (keysym-to-int nkey) nkey) | |
2206 | + nkey-state) | |
2207 | + #f ; Key event is consumed | |
2208 | + (begin | |
2209 | + (and mozc-use-with-vi? | |
2210 | + (mozc-vi-escape-key? key key-state) | |
2211 | + (mozc-lib-set-input-mode mc mid mozc-type-direct)) | |
2212 | + (im-commit-raw mc))))))))))) | |
2213 | + | |
2214 | +(define mozc-press-key-handler | |
2215 | + (lambda (mc key key-state) | |
2216 | + (if (mozc-context-on mc) | |
2217 | + (mozc-proc-input-state mc key key-state) | |
2218 | + (mozc-proc-direct-state mc key key-state)))) | |
2219 | + | |
2220 | +(define mozc-release-key-handler | |
2221 | + (lambda (mc key key-state) | |
2222 | + (if (or (ichar-control? key) | |
2223 | + (not (mozc-context-on mc))) | |
2224 | + (im-commit-raw mc)))) | |
2225 | + | |
2226 | +(define mozc-reset-handler | |
2227 | + (lambda (mc) | |
2228 | + (let ((mid (mozc-context-mc-id mc))) | |
2229 | + (mozc-lib-reset mid)))) | |
2230 | + | |
2231 | +(define mozc-focus-in-handler | |
2232 | + (lambda (mc) | |
2233 | + (let ((mid (mozc-context-mc-id mc))) | |
2234 | + ;(mozc-lib-focus-in mid) | |
2235 | + ))) | |
2236 | + | |
2237 | +(define mozc-focus-out-handler | |
2238 | + (lambda (mc) | |
2239 | + (let ((mid (mozc-context-mc-id mc))) | |
2240 | + ;(mozc-lib-focus-out mid) | |
2241 | + ))) | |
2242 | + | |
2243 | +(define mozc-get-candidate-handler | |
2244 | + (lambda (mc idx accel-enum-hint) | |
2245 | + (let* ((mid (mozc-context-mc-id mc)) | |
2246 | + (cand | |
2247 | + (mozc-lib-get-nth-candidate mid idx)) | |
2248 | + (label | |
2249 | + (mozc-lib-get-nth-label mid idx)) | |
2250 | + (annotation | |
2251 | + (mozc-lib-get-nth-annotation mid idx))) | |
2252 | + (list cand label annotation)))) | |
2253 | + | |
2254 | +(define mozc-set-candidate-index-handler | |
2255 | + (lambda (mc idx) | |
2256 | + (let ((mid (mozc-context-mc-id mc))) | |
2257 | + (mozc-lib-set-candidate-index mc mid idx)))) | |
2258 | + | |
2259 | +(mozc-configure-widgets) | |
2260 | + | |
2261 | +(register-im | |
2262 | + 'mozc | |
2263 | + "ja" | |
2264 | + "UTF-8" | |
2265 | + mozc-im-name-label | |
2266 | + mozc-im-short-desc | |
2267 | + #f | |
2268 | + mozc-init-handler | |
2269 | + mozc-release-handler | |
2270 | + context-mode-handler | |
2271 | + mozc-press-key-handler | |
2272 | + mozc-release-key-handler | |
2273 | + mozc-reset-handler | |
2274 | + mozc-get-candidate-handler | |
2275 | + mozc-set-candidate-index-handler | |
2276 | + context-prop-activate-handler | |
2277 | + #f | |
2278 | + #f ;mozc-focus-in-handler | |
2279 | + #f ;mozc-focus-out-handler | |
2280 | + #f | |
2281 | + #f | |
2282 | +) | |
2283 | diff --git a/unix/uim/uim.gyp b/unix/uim/uim.gyp | |
2284 | new file mode 100644 | |
2285 | index 0000000..7147a12 | |
2286 | --- /dev/null | |
2287 | +++ b/unix/uim/uim.gyp | |
2288 | @@ -0,0 +1,82 @@ | |
2289 | +# | |
2290 | +# Copyright (c) 2010 uim Project http://code.google.com/p/uim/ | |
2291 | +# | |
2292 | +# All rights reserved. | |
2293 | +# | |
2294 | +# Redistribution and use in source and binary forms, with or without | |
2295 | +# modification, are permitted provided that the following conditions | |
2296 | +# are met: | |
2297 | +# 1. Redistributions of source code must retain the above copyright | |
2298 | +# notice, this list of conditions and the following disclaimer. | |
2299 | +# 2. Redistributions in binary form must reproduce the above copyright | |
2300 | +# notice, this list of conditions and the following disclaimer in the | |
2301 | +# documentation and/or other materials provided with the distribution. | |
2302 | +# 3. Neither the name of authors nor the names of its contributors | |
2303 | +# may be used to endorse or promote products derived from this software | |
2304 | +# without specific prior written permission. | |
2305 | +# | |
2306 | +# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS ``AS IS'' AND | |
2307 | +# ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE | |
2308 | +# IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE | |
2309 | +# ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDERS OR CONTRIBUTORS BE LIABLE | |
2310 | +# FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL | |
2311 | +# DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS | |
2312 | +# OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) | |
2313 | +# HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT | |
2314 | +# LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY | |
2315 | +# OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF | |
2316 | +# SUCH DAMAGE. | |
2317 | +# | |
2318 | + | |
2319 | +{ | |
2320 | + 'variables': { | |
2321 | + 'relative_dir': 'unix/uim', | |
2322 | + 'pkg_config_libs': [ | |
2323 | + 'uim', | |
2324 | + ], | |
2325 | + 'uim_dep_include_dirs': [ | |
2326 | + ], | |
2327 | + 'uim_dependencies': [ | |
2328 | + '../../base/base.gyp:base', | |
2329 | + '../../client/client.gyp:client', | |
2330 | + ], | |
2331 | + }, | |
2332 | + 'targets': [ | |
2333 | + { | |
2334 | + 'target_name': 'uim_mozc_lib', | |
2335 | + 'type': 'static_library', | |
2336 | + 'sources': [ | |
2337 | + 'key_translator.cc', | |
2338 | + ], | |
2339 | + 'cflags': [ | |
2340 | + '<!@(pkg-config --cflags <@(pkg_config_libs))', | |
2341 | + ], | |
2342 | + 'include_dirs': [ | |
2343 | + '<@(uim_dep_include_dirs)', | |
2344 | + ], | |
2345 | + }, | |
2346 | + { | |
2347 | + 'target_name': 'uim-mozc', | |
2348 | + 'type': 'loadable_module', | |
2349 | + 'sources': [ | |
2350 | + 'mozc.cc', | |
2351 | + ], | |
2352 | + 'dependencies': [ | |
2353 | + '<@(uim_dependencies)', | |
2354 | + 'uim_mozc_lib', | |
2355 | + ], | |
2356 | + 'cflags': [ | |
2357 | + '<!@(pkg-config --cflags <@(pkg_config_libs))', | |
2358 | + ], | |
2359 | + 'include_dirs': [ | |
2360 | + '<@(uim_dep_include_dirs)', | |
2361 | + ], | |
2362 | + 'libraries': [ | |
2363 | + '<!@(pkg-config --libs-only-l <@(pkg_config_libs))', | |
2364 | + ], | |
2365 | + 'ldflags': [ | |
2366 | + '<!@(pkg-config --libs-only-L <@(pkg_config_libs))', | |
2367 | + ], | |
2368 | + }, | |
2369 | + ], | |
2370 | +} | |
2371 | -- | |
2372 | 1.7.1 | |
2373 |