Package list mozc / b23d03f
New upstream Signed-off-by: Nobuhiro Iwamatsu <iwamatsu@debian.org> Nobuhiro Iwamatsu 10 years ago
4 changed file(s) with 2385 addition(s) and 2376 deletion(s). Raw diff Collapse all Expand all
0 mozc (1.1.626.102-1) unstable; urgency=low
1
2 * New upstream release (r52).
3 * Update and add some patches.
4 - Update patch of uim-mozc (r222).
5 - Drop mozc-el-pseudo-cursor.patch.
6
7 -- Nobuhiro Iwamatsu <iwamatsu@debian.org> Tue, 15 Mar 2011 01:06:41 +0900
8
09 mozc (1.0.558.102-1) unstable; urgency=low
110
211 * New upstream release (r51).
+0
-2374
debian/patches/0002-Add-uim-mozc-r204.patch less more
0 From 0f6758681db88b560f9a5996e2ded2fa366f745b Mon Sep 17 00:00:00 2001
1 From: Nobuhiro Iwamatsu <iwamatsu@debian.org>
2 Date: Wed, 13 Oct 2010 08:04:22 +0900
3 Subject: [PATCH] Add uim-mozc r204
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 | 436 +++++++++++++++++
10 unix/uim/key_translator.h | 111 +++++
11 unix/uim/mozc.cc | 992 ++++++++++++++++++++++++++++++++++++++
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..ae1cd2d
28 --- /dev/null
29 +++ b/unix/uim/key_translator.cc
30 @@ -0,0 +1,436 @@
31 +// Copyright 2010, Google Inc.
32 +// Copyright (c) 2010 uim Project http://code.google.com/p/uim/
33 +// All rights reserved.
34 +//
35 +// Redistribution and use in source and binary forms, with or without
36 +// modification, are permitted provided that the following conditions are
37 +// met:
38 +//
39 +// * Redistributions of source code must retain the above copyright
40 +// notice, this list of conditions and the following disclaimer.
41 +// * Redistributions in binary form must reproduce the above
42 +// copyright notice, this list of conditions and the following disclaimer
43 +// in the documentation and/or other materials provided with the
44 +// distribution.
45 +// * Neither the name of authors nor the names of its
46 +// contributors may be used to endorse or promote products derived from
47 +// this software without specific prior written permission.
48 +//
49 +// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
50 +// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
51 +// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
52 +// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
53 +// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
54 +// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
55 +// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
56 +// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
57 +// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
58 +// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
59 +// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
60 +
61 +#include "unix/uim/key_translator.h"
62 +
63 +#include <uim.h>
64 +
65 +#include "base/logging.h"
66 +
67 +namespace {
68 +
69 +const struct SpecialKeyMap {
70 + unsigned int from;
71 + mozc::commands::KeyEvent::SpecialKey to;
72 +} special_key_map[] = {
73 + {0x20, mozc::commands::KeyEvent::SPACE},
74 + {UKey_Return, mozc::commands::KeyEvent::ENTER},
75 + {UKey_Left, mozc::commands::KeyEvent::LEFT},
76 + {UKey_Right, mozc::commands::KeyEvent::RIGHT},
77 + {UKey_Up, mozc::commands::KeyEvent::UP},
78 + {UKey_Down, mozc::commands::KeyEvent::DOWN},
79 + {UKey_Escape, mozc::commands::KeyEvent::ESCAPE},
80 + {UKey_Delete, mozc::commands::KeyEvent::DEL},
81 + {UKey_Backspace, mozc::commands::KeyEvent::BACKSPACE},
82 + {UKey_Insert, mozc::commands::KeyEvent::INSERT},
83 + {UKey_Henkan, mozc::commands::KeyEvent::HENKAN},
84 + {UKey_Muhenkan, mozc::commands::KeyEvent::MUHENKAN},
85 + {UKey_Hiragana, mozc::commands::KeyEvent::KANA},
86 + {UKey_Katakana, mozc::commands::KeyEvent::KANA},
87 + {UKey_Eisu_toggle, mozc::commands::KeyEvent::EISU},
88 + {UKey_Home, mozc::commands::KeyEvent::HOME},
89 + {UKey_End, mozc::commands::KeyEvent::END},
90 + {UKey_Tab, mozc::commands::KeyEvent::TAB},
91 + {UKey_F1, mozc::commands::KeyEvent::F1},
92 + {UKey_F2, mozc::commands::KeyEvent::F2},
93 + {UKey_F3, mozc::commands::KeyEvent::F3},
94 + {UKey_F4, mozc::commands::KeyEvent::F4},
95 + {UKey_F5, mozc::commands::KeyEvent::F5},
96 + {UKey_F6, mozc::commands::KeyEvent::F6},
97 + {UKey_F7, mozc::commands::KeyEvent::F7},
98 + {UKey_F8, mozc::commands::KeyEvent::F8},
99 + {UKey_F9, mozc::commands::KeyEvent::F9},
100 + {UKey_F10, mozc::commands::KeyEvent::F10},
101 + {UKey_F11, mozc::commands::KeyEvent::F11},
102 + {UKey_F12, mozc::commands::KeyEvent::F12},
103 + {UKey_F13, mozc::commands::KeyEvent::F13},
104 + {UKey_F14, mozc::commands::KeyEvent::F14},
105 + {UKey_F15, mozc::commands::KeyEvent::F15},
106 + {UKey_F16, mozc::commands::KeyEvent::F16},
107 + {UKey_F17, mozc::commands::KeyEvent::F17},
108 + {UKey_F18, mozc::commands::KeyEvent::F18},
109 + {UKey_F19, mozc::commands::KeyEvent::F19},
110 + {UKey_F20, mozc::commands::KeyEvent::F20},
111 + {UKey_F21, mozc::commands::KeyEvent::F21},
112 + {UKey_F22, mozc::commands::KeyEvent::F22},
113 + {UKey_F23, mozc::commands::KeyEvent::F23},
114 + {UKey_F24, mozc::commands::KeyEvent::F24},
115 + {UKey_Prior, mozc::commands::KeyEvent::PAGE_UP},
116 + {UKey_Next, mozc::commands::KeyEvent::PAGE_DOWN},
117 +};
118 +
119 +const struct ModifierKeyMap {
120 + unsigned int from;
121 + mozc::commands::KeyEvent::ModifierKey to;
122 +} modifier_key_map[] = {
123 + {UKey_Shift, mozc::commands::KeyEvent::SHIFT},
124 + {UKey_Control, mozc::commands::KeyEvent::CTRL},
125 + {UKey_Alt, mozc::commands::KeyEvent::ALT},
126 +};
127 +
128 +const struct ModifierMaskMap {
129 + unsigned int from;
130 + mozc::commands::KeyEvent::ModifierKey to;
131 +} modifier_mask_map[] = {
132 + {UMod_Shift, mozc::commands::KeyEvent::SHIFT},
133 + {UMod_Control, mozc::commands::KeyEvent::CTRL},
134 + {UMod_Alt, mozc::commands::KeyEvent::ALT},
135 +};
136 +
137 +// TODO:Add kana_map_dv to support Dvoraklayout.
138 +const struct KanaMap {
139 + unsigned int code;
140 + const char *no_shift;
141 + const char *shift;
142 +} kana_map_jp[] = {
143 + { '1' , "\xe3\x81\xac", "\xe3\x81\xac" }, // "ぬ", "ぬ"
144 + { '!' , "\xe3\x81\xac", "\xe3\x81\xac" }, // "ぬ", "ぬ"
145 + { '2' , "\xe3\x81\xb5", "\xe3\x81\xb5" }, // "ふ", "ふ"
146 + { '\"', "\xe3\x81\xb5", "\xe3\x81\xb5" }, // "ふ", "ふ"
147 + { '3' , "\xe3\x81\x82", "\xe3\x81\x81" }, // "あ", "ぁ"
148 + { '#' , "\xe3\x81\x81", "\xe3\x81\x81" }, // "ぁ", "ぁ"
149 + { '4' , "\xe3\x81\x86", "\xe3\x81\x85" }, // "う", "ぅ"
150 + { '$' , "\xe3\x81\x85", "\xe3\x81\x85" }, // "ぅ", "ぅ"
151 + { '5' , "\xe3\x81\x88", "\xe3\x81\x87" }, // "え", "ぇ"
152 + { '%' , "\xe3\x81\x87", "\xe3\x81\x87" }, // "ぇ", "ぇ"
153 + { '6' , "\xe3\x81\x8a", "\xe3\x81\x89" }, // "お", "ぉ"
154 + { '&' , "\xe3\x81\x89", "\xe3\x81\x89" }, // "ぉ", "ぉ"
155 + { '7' , "\xe3\x82\x84", "\xe3\x82\x83" }, // "や", "ゃ"
156 + { '\'', "\xe3\x82\x83", "\xe3\x82\x83" }, // "ゃ", "ゃ"
157 + { '8' , "\xe3\x82\x86", "\xe3\x82\x85" }, // "ゆ", "ゅ"
158 + { '(' , "\xe3\x82\x85", "\xe3\x82\x85" }, // "ゅ", "ゅ"
159 + { '9' , "\xe3\x82\x88", "\xe3\x82\x87" }, // "よ", "ょ"
160 + { ')' , "\xe3\x82\x87", "\xe3\x82\x87" }, // "ょ", "ょ"
161 + { '0' , "\xe3\x82\x8f", "\xe3\x82\x92" }, // "わ", "を"
162 + { '-' , "\xe3\x81\xbb", "\xe3\x81\xbb" }, // "ほ", "ほ"
163 + { '=' , "\xe3\x81\xbb", "\xe3\x81\xbb" }, // "ほ", "ほ"
164 + { '^' , "\xe3\x81\xb8", "\xe3\x81\xb8" }, // "へ", "へ"
165 + { '~' , "\xe3\x82\x92", "\xe3\x82\x92" }, // "を", "を"
166 + { '|' , "\xe3\x83\xbc", "\xe3\x83\xbc" }, // "ー", "ー"
167 + { 'q' , "\xe3\x81\x9f", "\xe3\x81\x9f" }, // "た", "た"
168 + { 'Q' , "\xe3\x81\x9f", "\xe3\x81\x9f" }, // "た", "た"
169 + { 'w' , "\xe3\x81\xa6", "\xe3\x81\xa6" }, // "て", "て"
170 + { 'W' , "\xe3\x81\xa6", "\xe3\x81\xa6" }, // "て", "て"
171 + { 'e' , "\xe3\x81\x84", "\xe3\x81\x83" }, // "い", "ぃ"
172 + { 'E' , "\xe3\x81\x83", "\xe3\x81\x83" }, // "ぃ", "ぃ"
173 + { 'r' , "\xe3\x81\x99", "\xe3\x81\x99" }, // "す", "す"
174 + { 'R' , "\xe3\x81\x99", "\xe3\x81\x99" }, // "す", "す"
175 + { 't' , "\xe3\x81\x8b", "\xe3\x81\x8b" }, // "か", "か"
176 + { 'T' , "\xe3\x81\x8b", "\xe3\x81\x8b" }, // "か", "か"
177 + { 'y' , "\xe3\x82\x93", "\xe3\x82\x93" }, // "ん", "ん"
178 + { 'Y' , "\xe3\x82\x93", "\xe3\x82\x93" }, // "ん", "ん"
179 + { 'u' , "\xe3\x81\xaa", "\xe3\x81\xaa" }, // "な", "な"
180 + { 'U' , "\xe3\x81\xaa", "\xe3\x81\xaa" }, // "な", "な"
181 + { 'i' , "\xe3\x81\xab", "\xe3\x81\xab" }, // "に", "に"
182 + { 'I' , "\xe3\x81\xab", "\xe3\x81\xab" }, // "に", "に"
183 + { 'o' , "\xe3\x82\x89", "\xe3\x82\x89" }, // "ら", "ら"
184 + { 'O' , "\xe3\x82\x89", "\xe3\x82\x89" }, // "ら", "ら"
185 + { 'p' , "\xe3\x81\x9b", "\xe3\x81\x9b" }, // "せ", "せ"
186 + { 'P' , "\xe3\x81\x9b", "\xe3\x81\x9b" }, // "せ", "せ"
187 + { '@' , "\xe3\x82\x9b", "\xe3\x82\x9b" }, // "゛", "゛"
188 + { '`' , "\xe3\x82\x9b", "\xe3\x82\x9b" }, // "゛", "゛"
189 + { '[' , "\xe3\x82\x9c", "\xe3\x80\x8c" }, // "゜", "「"
190 + { '{' , "\xe3\x82\x9c", "\xe3\x80\x8c" }, // "゜", "「"
191 + { 'a' , "\xe3\x81\xa1", "\xe3\x81\xa1" }, // "ち", "ち"
192 + { 'A' , "\xe3\x81\xa1", "\xe3\x81\xa1" }, // "ち", "ち"
193 + { 's' , "\xe3\x81\xa8", "\xe3\x81\xa8" }, // "と", "と"
194 + { 'S' , "\xe3\x81\xa8", "\xe3\x81\xa8" }, // "と", "と"
195 + { 'd' , "\xe3\x81\x97", "\xe3\x81\x97" }, // "し", "し"
196 + { 'D' , "\xe3\x81\x97", "\xe3\x81\x97" }, // "し", "し"
197 + { 'f' , "\xe3\x81\xaf", "\xe3\x81\xaf" }, // "は", "は"
198 + { 'F' , "\xe3\x81\xaf", "\xe3\x81\xaf" }, // "は", "は"
199 + { 'g' , "\xe3\x81\x8d", "\xe3\x81\x8d" }, // "き", "き"
200 + { 'G' , "\xe3\x81\x8d", "\xe3\x81\x8d" }, // "き", "き"
201 + { 'h' , "\xe3\x81\x8f", "\xe3\x81\x8f" }, // "く", "く"
202 + { 'H' , "\xe3\x81\x8f", "\xe3\x81\x8f" }, // "く", "く"
203 + { 'j' , "\xe3\x81\xbe", "\xe3\x81\xbe" }, // "ま", "ま"
204 + { 'J' , "\xe3\x81\xbe", "\xe3\x81\xbe" }, // "ま", "ま"
205 + { 'k' , "\xe3\x81\xae", "\xe3\x81\xae" }, // "の", "の"
206 + { 'K' , "\xe3\x81\xae", "\xe3\x81\xae" }, // "の", "の"
207 + { 'l' , "\xe3\x82\x8a", "\xe3\x82\x8a" }, // "り", "り"
208 + { 'L' , "\xe3\x82\x8a", "\xe3\x82\x8a" }, // "り", "り"
209 + { ';' , "\xe3\x82\x8c", "\xe3\x82\x8c" }, // "れ", "れ"
210 + { '+' , "\xe3\x82\x8c", "\xe3\x82\x8c" }, // "れ", "れ"
211 + { ':' , "\xe3\x81\x91", "\xe3\x81\x91" }, // "け", "け"
212 + { '*' , "\xe3\x81\x91", "\xe3\x81\x91" }, // "け", "け"
213 + { ']' , "\xe3\x82\x80", "\xe3\x80\x8d" }, // "む", "」"
214 + { '}' , "\xe3\x80\x8d", "\xe3\x80\x8d" }, // "」", "」"
215 + { 'z' , "\xe3\x81\xa4", "\xe3\x81\xa3" }, // "つ", "っ"
216 + { 'Z' , "\xe3\x81\xa3", "\xe3\x81\xa3" }, // "っ", "っ"
217 + { 'x' , "\xe3\x81\x95", "\xe3\x81\x95" }, // "さ", "さ"
218 + { 'X' , "\xe3\x81\x95", "\xe3\x81\x95" }, // "さ", "さ"
219 + { 'c' , "\xe3\x81\x9d", "\xe3\x81\x9d" }, // "そ", "そ"
220 + { 'C' , "\xe3\x81\x9d", "\xe3\x81\x9d" }, // "そ", "そ"
221 + { 'v' , "\xe3\x81\xb2", "\xe3\x81\xb2" }, // "ひ", "ひ"
222 + { 'V' , "\xe3\x81\xb2", "\xe3\x81\xb2" }, // "ひ", "ひ"
223 + { 'b' , "\xe3\x81\x93", "\xe3\x81\x93" }, // "こ", "こ"
224 + { 'B' , "\xe3\x81\x93", "\xe3\x81\x93" }, // "こ", "こ"
225 + { 'n' , "\xe3\x81\xbf", "\xe3\x81\xbf" }, // "み", "み"
226 + { 'N' , "\xe3\x81\xbf", "\xe3\x81\xbf" }, // "み", "み"
227 + { 'm' , "\xe3\x82\x82", "\xe3\x82\x82" }, // "も", "も"
228 + { 'M' , "\xe3\x82\x82", "\xe3\x82\x82" }, // "も", "も"
229 + { ',' , "\xe3\x81\xad", "\xe3\x80\x81" }, // "ね", "、"
230 + { '<' , "\xe3\x80\x81", "\xe3\x80\x81" }, // "、", "、"
231 + { '.' , "\xe3\x82\x8b", "\xe3\x80\x82" }, // "る", "。"
232 + { '>' , "\xe3\x80\x82", "\xe3\x80\x82" }, // "。", "。"
233 + { '/' , "\xe3\x82\x81", "\xe3\x83\xbb" }, // "め", "・"
234 + { '?' , "\xe3\x83\xbb", "\xe3\x83\xbb" }, // "・", "・"
235 + { '_' , "\xe3\x82\x8d", "\xe3\x82\x8d" }, // "ろ", "ろ"
236 + // uim distinguishes backslash key and yen key
237 + { '\\', "\xe3\x82\x8d", "\xe3\x82\x8d" }, // "ろ", "ろ"
238 + { UKey_Yen, "\xe3\x83\xbc", "\xe3\x83\xbc" }, // "ー", "ー"
239 +}, kana_map_us[] = {
240 + { '`' , "\xe3\x82\x8d", "\xe3\x82\x8d" }, // "ろ", "ろ"
241 + { '~' , "\xe3\x82\x8d", "\xe3\x82\x8d" }, // "ろ", "ろ"
242 + { '1' , "\xe3\x81\xac", "\xe3\x81\xac" }, // "ぬ", "ぬ"
243 + { '!' , "\xe3\x81\xac", "\xe3\x81\xac" }, // "ぬ", "ぬ"
244 + { '2' , "\xe3\x81\xb5", "\xe3\x81\xb5" }, // "ふ", "ふ"
245 + { '@' , "\xe3\x81\xb5", "\xe3\x81\xb5" }, // "ふ", "ふ"
246 + { '3' , "\xe3\x81\x82", "\xe3\x81\x81" }, // "あ", "ぁ"
247 + { '#' , "\xe3\x81\x81", "\xe3\x81\x81" }, // "ぁ", "ぁ"
248 + { '4' , "\xe3\x81\x86", "\xe3\x81\x85" }, // "う", "ぅ"
249 + { '$' , "\xe3\x81\x85", "\xe3\x81\x85" }, // "ぅ", "ぅ"
250 + { '5' , "\xe3\x81\x88", "\xe3\x81\x87" }, // "え", "ぇ"
251 + { '%' , "\xe3\x81\x87", "\xe3\x81\x87" }, // "ぇ", "ぇ"
252 + { '6' , "\xe3\x81\x8a", "\xe3\x81\x89" }, // "お", "ぉ"
253 + { '^' , "\xe3\x81\x89", "\xe3\x81\x89" }, // "ぉ", "ぉ"
254 + { '7' , "\xe3\x82\x84", "\xe3\x82\x83" }, // "や", "ゃ"
255 + { '&' , "\xe3\x82\x83", "\xe3\x82\x83" }, // "ゃ", "ゃ"
256 + { '8' , "\xe3\x82\x86", "\xe3\x82\x85" }, // "ゆ", "ゅ"
257 + { '*' , "\xe3\x82\x85", "\xe3\x82\x85" }, // "ゅ", "ゅ"
258 + { '9' , "\xe3\x82\x88", "\xe3\x82\x87" }, // "よ", "ょ"
259 + { '(' , "\xe3\x82\x87", "\xe3\x82\x87" }, // "ょ", "ょ"
260 + { '0' , "\xe3\x82\x8f", "\xe3\x82\x92" }, // "わ", "を"
261 + { ')' , "\xe3\x82\x92", "\xe3\x82\x92" }, // "を", "を"
262 + { '-' , "\xe3\x81\xbb", "\xe3\x83\xbc" }, // "ほ", "ー"
263 + { '_' , "\xe3\x83\xbc", "\xe3\x83\xbc" }, // "ー", "ー"
264 + { '=' , "\xe3\x81\xb8", "\xe3\x81\xb8" }, // "へ", "へ"
265 + { '+' , "\xe3\x81\xb8", "\xe3\x81\xb8" }, // "へ", "へ"
266 + { 'q' , "\xe3\x81\x9f", "\xe3\x81\x9f" }, // "た", "た"
267 + { 'Q' , "\xe3\x81\x9f", "\xe3\x81\x9f" }, // "た", "た"
268 + { 'w' , "\xe3\x81\xa6", "\xe3\x81\xa6" }, // "て", "て"
269 + { 'W' , "\xe3\x81\xa6", "\xe3\x81\xa6" }, // "て", "て"
270 + { 'e' , "\xe3\x81\x84", "\xe3\x81\x83" }, // "い", "ぃ"
271 + { 'E' , "\xe3\x81\x83", "\xe3\x81\x83" }, // "ぃ", "ぃ"
272 + { 'r' , "\xe3\x81\x99", "\xe3\x81\x99" }, // "す", "す"
273 + { 'R' , "\xe3\x81\x99", "\xe3\x81\x99" }, // "す", "す"
274 + { 't' , "\xe3\x81\x8b", "\xe3\x81\x8b" }, // "か", "か"
275 + { 'T' , "\xe3\x81\x8b", "\xe3\x81\x8b" }, // "か", "か"
276 + { 'y' , "\xe3\x82\x93", "\xe3\x82\x93" }, // "ん", "ん"
277 + { 'Y' , "\xe3\x82\x93", "\xe3\x82\x93" }, // "ん", "ん"
278 + { 'u' , "\xe3\x81\xaa", "\xe3\x81\xaa" }, // "な", "な"
279 + { 'U' , "\xe3\x81\xaa", "\xe3\x81\xaa" }, // "な", "な"
280 + { 'i' , "\xe3\x81\xab", "\xe3\x81\xab" }, // "に", "に"
281 + { 'I' , "\xe3\x81\xab", "\xe3\x81\xab" }, // "に", "に"
282 + { 'o' , "\xe3\x82\x89", "\xe3\x82\x89" }, // "ら", "ら"
283 + { 'O' , "\xe3\x82\x89", "\xe3\x82\x89" }, // "ら", "ら"
284 + { 'p' , "\xe3\x81\x9b", "\xe3\x81\x9b" }, // "せ", "せ"
285 + { 'P' , "\xe3\x81\x9b", "\xe3\x81\x9b" }, // "せ", "せ"
286 + { '[' , "\xe3\x82\x9b", "\xe3\x82\x9b" }, // "゛", "゛"
287 + { '{' , "\xe3\x82\x9b", "\xe3\x82\x9b" }, // "゛", "゛"
288 + { ']' , "\xe3\x82\x9c", "\xe3\x80\x8c" }, // "゜", "「"
289 + { '}' , "\xe3\x80\x8c", "\xe3\x80\x8c" }, // "「", "「"
290 + { '\\', "\xe3\x82\x80", "\xe3\x80\x8d" }, // "む", "」"
291 + { '|' , "\xe3\x80\x8d", "\xe3\x80\x8d" }, // "」", "」"
292 + { 'a' , "\xe3\x81\xa1", "\xe3\x81\xa1" }, // "ち", "ち"
293 + { 'A' , "\xe3\x81\xa1", "\xe3\x81\xa1" }, // "ち", "ち"
294 + { 's' , "\xe3\x81\xa8", "\xe3\x81\xa8" }, // "と", "と"
295 + { 'S' , "\xe3\x81\xa8", "\xe3\x81\xa8" }, // "と", "と"
296 + { 'd' , "\xe3\x81\x97", "\xe3\x81\x97" }, // "し", "し"
297 + { 'D' , "\xe3\x81\x97", "\xe3\x81\x97" }, // "し", "し"
298 + { 'f' , "\xe3\x81\xaf", "\xe3\x81\xaf" }, // "は", "は"
299 + { 'F' , "\xe3\x81\xaf", "\xe3\x81\xaf" }, // "は", "は"
300 + { 'g' , "\xe3\x81\x8d", "\xe3\x81\x8d" }, // "き", "き"
301 + { 'G' , "\xe3\x81\x8d", "\xe3\x81\x8d" }, // "き", "き"
302 + { 'h' , "\xe3\x81\x8f", "\xe3\x81\x8f" }, // "く", "く"
303 + { 'H' , "\xe3\x81\x8f", "\xe3\x81\x8f" }, // "く", "く"
304 + { 'j' , "\xe3\x81\xbe", "\xe3\x81\xbe" }, // "ま", "ま"
305 + { 'J' , "\xe3\x81\xbe", "\xe3\x81\xbe" }, // "ま", "ま"
306 + { 'k' , "\xe3\x81\xae", "\xe3\x81\xae" }, // "の", "の"
307 + { 'K' , "\xe3\x81\xae", "\xe3\x81\xae" }, // "の", "の"
308 + { 'l' , "\xe3\x82\x8a", "\xe3\x82\x8a" }, // "り", "り"
309 + { 'L' , "\xe3\x82\x8a", "\xe3\x82\x8a" }, // "り", "り"
310 + { ';' , "\xe3\x82\x8c", "\xe3\x82\x8c" }, // "れ", "れ"
311 + { ':' , "\xe3\x82\x8c", "\xe3\x82\x8c" }, // "れ", "れ"
312 + { '\'', "\xe3\x81\x91", "\xe3\x81\x91" }, // "け", "け"
313 + { '\"', "\xe3\x81\x91", "\xe3\x81\x91" }, // "け", "け"
314 + { 'z' , "\xe3\x81\xa4", "\xe3\x81\xa3" }, // "つ", "っ"
315 + { 'Z' , "\xe3\x81\xa3", "\xe3\x81\xa3" }, // "っ", "っ"
316 + { 'x' , "\xe3\x81\x95", "\xe3\x81\x95" }, // "さ", "さ"
317 + { 'X' , "\xe3\x81\x95", "\xe3\x81\x95" }, // "さ", "さ"
318 + { 'c' , "\xe3\x81\x9d", "\xe3\x81\x9d" }, // "そ", "そ"
319 + { 'C' , "\xe3\x81\x9d", "\xe3\x81\x9d" }, // "そ", "そ"
320 + { 'v' , "\xe3\x81\xb2", "\xe3\x81\xb2" }, // "ひ", "ひ"
321 + { 'V' , "\xe3\x81\xb2", "\xe3\x81\xb2" }, // "ひ", "ひ"
322 + { 'b' , "\xe3\x81\x93", "\xe3\x81\x93" }, // "こ", "こ"
323 + { 'B' , "\xe3\x81\x93", "\xe3\x81\x93" }, // "こ", "こ"
324 + { 'n' , "\xe3\x81\xbf", "\xe3\x81\xbf" }, // "み", "み"
325 + { 'N' , "\xe3\x81\xbf", "\xe3\x81\xbf" }, // "み", "み"
326 + { 'm' , "\xe3\x82\x82", "\xe3\x82\x82" }, // "も", "も"
327 + { 'M' , "\xe3\x82\x82", "\xe3\x82\x82" }, // "も", "も"
328 + { ',' , "\xe3\x81\xad", "\xe3\x80\x81" }, // "ね", "、"
329 + { '<' , "\xe3\x80\x81", "\xe3\x80\x81" }, // "、", "、"
330 + { '.' , "\xe3\x82\x8b", "\xe3\x80\x82" }, // "る", "。"
331 + { '>' , "\xe3\x80\x82", "\xe3\x80\x82" }, // "。", "。"
332 + { '/' , "\xe3\x82\x81", "\xe3\x83\xbb" }, // "め", "・"
333 + { '?' , "\xe3\x83\xbb", "\xe3\x83\xbb" }, // "・", "・"
334 + { UKey_Yen, "\xe3\x83\xbc", "\xe3\x83\xbc" }, // "ー", "ー"
335 +};
336 +
337 +} // namespace
338 +
339 +namespace mozc {
340 +namespace uim {
341 +
342 +KeyTranslator::KeyTranslator() {
343 + Init();
344 +}
345 +
346 +KeyTranslator::~KeyTranslator() {
347 +}
348 +
349 +bool KeyTranslator::Translate(unsigned int keyval,
350 + unsigned int keycode,
351 + unsigned int modifiers,
352 + config::Config::PreeditMethod method,
353 + bool layout_is_jp,
354 + commands::KeyEvent *out_event) const {
355 + DCHECK(out_event) << "out_event is NULL";
356 + out_event->Clear();
357 +
358 + string kana_key_string;
359 + if ((method == config::Config::KANA) && IsKanaAvailable(
360 + keyval, keycode, modifiers, layout_is_jp, &kana_key_string)) {
361 + out_event->set_key_code(keyval);
362 + out_event->set_key_string(kana_key_string);
363 + } else if (IsAscii(keyval, keycode, modifiers)) {
364 + out_event->set_key_code(keyval);
365 + } else if (IsModifierKey(keyval, keycode, modifiers)) {
366 + ModifierKeyMap::const_iterator i = modifier_key_map_.find(keyval);
367 + DCHECK(i != modifier_key_map_.end());
368 + out_event->add_modifier_keys((*i).second);
369 + } else if (IsSpecialKey(keyval, keycode, modifiers)) {
370 + SpecialKeyMap::const_iterator i = special_key_map_.find(keyval);
371 + DCHECK(i != special_key_map_.end());
372 + out_event->set_special_key((*i).second);
373 + } else if ((method == config::Config::ROMAN) && keyval == UKey_Yen) {
374 + /* regards yen key as backslash */
375 + out_event->set_key_code('\\');
376 + } else {
377 + VLOG(1) << "Unknown keyval: " << keyval;
378 + return false;
379 + }
380 +
381 + for (ModifierKeyMap::const_iterator i = modifier_mask_map_.begin();
382 + i != modifier_mask_map_.end();
383 + ++i) {
384 + // Do not set a SHIFT modifier when |keyval| is a printable key by following
385 + // the Mozc's rule.
386 + if (((*i).second == commands::KeyEvent::SHIFT) &&
387 + IsAscii(keyval, keycode, modifiers)) {
388 + continue;
389 + }
390 +
391 + if ((*i).first & modifiers) {
392 + out_event->add_modifier_keys((*i).second);
393 + }
394 + }
395 +
396 + return true;
397 +}
398 +
399 +void KeyTranslator::Init() {
400 + for (int i = 0; i < arraysize(special_key_map); ++i) {
401 + CHECK(special_key_map_.insert(make_pair(special_key_map[i].from,
402 + special_key_map[i].to)).second);
403 + }
404 + for (int i = 0; i < arraysize(modifier_key_map); ++i) {
405 + CHECK(modifier_key_map_.insert(make_pair(modifier_key_map[i].from,
406 + modifier_key_map[i].to)).second);
407 + }
408 + for (int i = 0; i < arraysize(modifier_mask_map); ++i) {
409 + CHECK(modifier_mask_map_.insert(make_pair(modifier_mask_map[i].from,
410 + modifier_mask_map[i].to)).second);
411 + }
412 + for (int i = 0; i < arraysize(kana_map_jp); ++i) {
413 + CHECK(kana_map_jp_.insert(
414 + make_pair(kana_map_jp[i].code, make_pair(
415 + kana_map_jp[i].no_shift, kana_map_jp[i].shift))).second);
416 + }
417 + for (int i = 0; i < arraysize(kana_map_us); ++i) {
418 + CHECK(kana_map_us_.insert(
419 + make_pair(kana_map_us[i].code, make_pair(
420 + kana_map_us[i].no_shift, kana_map_us[i].shift))).second);
421 + }
422 +}
423 +
424 +bool KeyTranslator::IsModifierKey(unsigned int keyval,
425 + unsigned int keycode,
426 + unsigned int modifiers) const {
427 + return modifier_key_map_.find(keyval) != modifier_key_map_.end();
428 +}
429 +
430 +bool KeyTranslator::IsSpecialKey(unsigned int keyval,
431 + unsigned int keycode,
432 + unsigned int modifiers) const {
433 + return special_key_map_.find(keyval) != special_key_map_.end();
434 +}
435 +
436 +bool KeyTranslator::IsKanaAvailable(unsigned int keyval,
437 + unsigned int keycode,
438 + unsigned int modifiers,
439 + bool layout_is_jp,
440 + string *out) const {
441 + if ((modifiers & UMod_Control) || (modifiers & UMod_Alt)) {
442 + return false;
443 + }
444 + const KanaMap &kana_map = layout_is_jp ? kana_map_jp_ : kana_map_us_;
445 + KanaMap::const_iterator iter = kana_map.find(keyval);
446 + if (iter == kana_map.end()) {
447 + return false;
448 + }
449 +
450 + if (out)
451 + *out = (modifiers & UMod_Shift) ?
452 + iter->second.second : iter->second.first;
453 +
454 + return true;
455 +}
456 +
457 +bool KeyTranslator::IsAscii(unsigned int keyval,
458 + unsigned int keycode,
459 + unsigned int modifiers) {
460 + return (keyval > 0x20 &&
461 + // Note: Space key (0x20) is a special key in Mozc.
462 + keyval <= 0x7e); // ~
463 +}
464 +
465 +} // namespace uim
466 +} // namespace mozc
467 diff --git a/unix/uim/key_translator.h b/unix/uim/key_translator.h
468 new file mode 100644
469 index 0000000..be58c9b
470 --- /dev/null
471 +++ b/unix/uim/key_translator.h
472 @@ -0,0 +1,111 @@
473 +// Copyright 2010, Google Inc.
474 +// Copyright (c) 2010 uim Project http://code.google.com/p/uim/
475 +// All rights reserved.
476 +//
477 +// Redistribution and use in source and binary forms, with or without
478 +// modification, are permitted provided that the following conditions are
479 +// met:
480 +//
481 +// * Redistributions of source code must retain the above copyright
482 +// notice, this list of conditions and the following disclaimer.
483 +// * Redistributions in binary form must reproduce the above
484 +// copyright notice, this list of conditions and the following disclaimer
485 +// in the documentation and/or other materials provided with the
486 +// distribution.
487 +// * Neither the name of authors nor the names of its
488 +// contributors may be used to endorse or promote products derived from
489 +// this software without specific prior written permission.
490 +//
491 +// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
492 +// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
493 +// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
494 +// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
495 +// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
496 +// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
497 +// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
498 +// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
499 +// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
500 +// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
501 +// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
502 +
503 +#ifndef MOZC_UNIX_UIM_KEY_TRANSLATOR_H_
504 +#define MOZC_UNIX_UIM_KEY_TRANSLATOR_H_
505 +
506 +#include <uim.h>
507 +
508 +#include <map>
509 +#include <ext/hash_map>
510 +using __gnu_cxx::hash_map;
511 +
512 +#include "base/base.h"
513 +#include "session/commands.pb.h"
514 +
515 +namespace mozc {
516 +namespace uim {
517 +
518 +// This class is responsible for converting key code sent from ibus-daemon
519 +// (defined in /usr/include/ibus-1.0/ibuskeysyms.h) to a KeyEvent object for
520 +// the input of session_interface.
521 +class KeyTranslator {
522 + public:
523 + KeyTranslator();
524 + virtual ~KeyTranslator();
525 +
526 + // Converts ibus keycode to Mozc key code and stores them on |out_event|.
527 + // Returns true if ibus keycode is successfully converted to Mozc key code.
528 + bool Translate(unsigned int keyval,
529 + unsigned int keycode,
530 + unsigned int modifiers,
531 + config::Config::PreeditMethod method,
532 + bool layout_is_jp,
533 + commands::KeyEvent *out_event) const;
534 +
535 + private:
536 + typedef hash_map<unsigned int, commands::KeyEvent::SpecialKey> SpecialKeyMap;
537 + typedef map<unsigned int, commands::KeyEvent::ModifierKey> ModifierKeyMap;
538 + typedef map<unsigned int, pair<string, string> > KanaMap;
539 +
540 + // Returns true iff key is modifier key such as SHIFT, ALT, or CAPSLOCK.
541 + bool IsModifierKey(unsigned int keyval,
542 + unsigned int keycode,
543 + unsigned int modifiers) const;
544 +
545 + // Returns true iff key is special key such as ENTER, ESC, or PAGE_UP.
546 + bool IsSpecialKey(unsigned int keyval,
547 + unsigned int keycode,
548 + unsigned int modifiers) const;
549 + // Returns true iff |keyval| is a key with a kana assigned.
550 + bool IsKanaAvailable(unsigned int keyval,
551 + unsigned int keycode,
552 + unsigned int modifiers,
553 + bool layout_is_jp,
554 + string *out) const;
555 +
556 +
557 + // Returns true iff key is ASCII such as '0', 'A', or '!'.
558 + static bool IsAscii(unsigned int keyval,
559 + unsigned int keycode,
560 + unsigned int modifiers);
561 +
562 + // Initializes private fields.
563 + void Init();
564 +
565 + // Stores a mapping from ibus keys to Mozc's special keys.
566 + SpecialKeyMap special_key_map_;
567 + // Stores a mapping from ibus modifier keys to Mozc's modifier keys.
568 + ModifierKeyMap modifier_key_map_;
569 + // Stores a mapping from ibus modifier masks to Mozc's modifier keys.
570 + ModifierKeyMap modifier_mask_map_;
571 + // Stores a mapping from ASCII to Kana character. For example, ASCII character
572 + // '4' is mapped to Japanese 'Hiragana Letter U' (without Shift modifier) and
573 + // 'Hiragana Letter Small U' (with Shift modifier).
574 + KanaMap kana_map_jp_; // mapping for JP keyboard.
575 + KanaMap kana_map_us_; // mapping for US keyboard.
576 +
577 + DISALLOW_COPY_AND_ASSIGN(KeyTranslator);
578 +};
579 +
580 +} // namespace uim
581 +} // namespace mozc
582 +
583 +#endif // MOZC_UNIX_UIM_KEY_TRANSLATOR_H_
584 diff --git a/unix/uim/mozc.cc b/unix/uim/mozc.cc
585 new file mode 100644
586 index 0000000..80d54fa
587 --- /dev/null
588 +++ b/unix/uim/mozc.cc
589 @@ -0,0 +1,992 @@
590 +/*
591 +
592 + Copyright (c) 2010 uim Project http://code.google.com/p/uim/
593 +
594 + All rights reserved.
595 +
596 + Redistribution and use in source and binary forms, with or without
597 + modification, are permitted provided that the following conditions
598 + are met:
599 +
600 + 1. Redistributions of source code must retain the above copyright
601 + notice, this list of conditions and the following disclaimer.
602 + 2. Redistributions in binary form must reproduce the above copyright
603 + notice, this list of conditions and the following disclaimer in the
604 + documentation and/or other materials provided with the distribution.
605 + 3. Neither the name of authors nor the names of its contributors
606 + may be used to endorse or promote products derived from this software
607 + without specific prior written permission.
608 +
609 + THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS ``AS IS'' AND
610 + ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
611 + IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
612 + ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDERS OR CONTRIBUTORS BE LIABLE
613 + FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
614 + DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
615 + OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
616 + HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
617 + LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
618 + OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
619 + SUCH DAMAGE.
620 +
621 +*/
622 +
623 +//#include <config.h>
624 +
625 +#include <stdio.h>
626 +#include <stdlib.h>
627 +#include <string.h>
628 +#include <ctype.h>
629 +
630 +#include "uim.h"
631 +#include "uim-scm.h"
632 +#include "uim-scm-abbrev.h"
633 +#include "uim-util.h"
634 +#if UIM_VERSION_REQUIRE(1, 6, 0)
635 +# include "dynlib.h"
636 +#else
637 +# include "plugin.h"
638 +#endif
639 +
640 +#include "base/base.h"
641 +#include "base/util.h"
642 +#include "base/scoped_ptr.h"
643 +#include "session/config.pb.h"
644 +#include "session/commands.pb.h"
645 +#include "client/session.h"
646 +#include "unix/uim/key_translator.h"
647 +
648 +// use server/client session
649 +#include "base/util.h"
650 +#include "client/session.h"
651 +
652 +#define USE_CASCADING_CANDIDATES 0
653 +
654 +#include <map>
655 +#include <ext/hash_map>
656 +using __gnu_cxx::hash_map;
657 +static char **argv;
658 +
659 +// for every 5 minutes, call SyncData
660 +const uint64 kSyncDataInterval = 5 * 60;
661 +// An ID for a candidate which is not associated with a text.
662 +const int32 kBadCandidateId = -1;
663 +
664 +uint64 GetTime() {
665 + return static_cast<uint64>(time(NULL));
666 +}
667 +
668 +namespace mozc {
669 +
670 +namespace client {
671 +class SessionInterface;
672 +}
673 +namespace uim {
674 +
675 +static int nr_contexts;
676 +static struct context_slot_ {
677 + client::SessionInterface *session;
678 + commands::Output *output;
679 + commands::CompositionMode currentMode;
680 + bool has_preedit_before;
681 + int cand_nr_before;
682 + uint64 last_sync_time;
683 +#if USE_CASCADING_CANDIDATES
684 + vector<int32> *unique_candidate_ids;
685 +#endif
686 + config::Config::PreeditMethod preedit_method;
687 +} *context_slot;
688 +
689 +static KeyTranslator *keyTranslator;
690 +
691 +static int
692 +unused_context_id(void)
693 +{
694 + int i;
695 +
696 + for (i = 0; i < nr_contexts; i++) {
697 + if (!context_slot[i].session)
698 + return i;
699 + }
700 +
701 + nr_contexts++;
702 + context_slot = (context_slot_ *)uim_realloc(context_slot, sizeof(struct context_slot_) * (nr_contexts));
703 +
704 + return i;
705 +}
706 +
707 +static void
708 +SyncData(int id, bool force)
709 +{
710 + if (context_slot[id].session == NULL)
711 + return;
712 +
713 + const uint64 current_time = GetTime();
714 + if (force ||
715 + (current_time >= context_slot[id].last_sync_time &&
716 + current_time - context_slot[id].last_sync_time >= kSyncDataInterval)) {
717 + context_slot[id].session->SyncData();
718 + context_slot[id].last_sync_time = current_time;
719 + }
720 +}
721 +
722 +static void
723 +update_result(uim_lisp mc_, int id)
724 +{
725 + commands::Output *output = context_slot[id].output;
726 +
727 + if (!output->has_result())
728 + return;
729 +
730 + const char *str = output->result().value().c_str();
731 + uim_scm_callf("im-commit", "os", mc_, str);
732 +}
733 +
734 +static uim_lisp
735 +insert_cursor(uim_lisp segs, const commands::Preedit::Segment &segment, int attr, int pos)
736 +{
737 + size_t len = segment.value_length();
738 +
739 + string former = Util::SubString(segment.value(), 0, pos);
740 + string latter = Util::SubString(segment.value(), pos, len);
741 +
742 + uim_lisp seg_f, seg_c, seg_l;
743 + if (pos == 0) {
744 + seg_f = uim_scm_null(); /* not used */
745 + seg_c = CONS(MAKE_INT(UPreeditAttr_Cursor), MAKE_STR(""));
746 + seg_l = CONS(MAKE_INT(attr), MAKE_STR(latter.c_str()));
747 +
748 + segs = CONS(seg_c, segs);
749 + segs = CONS(seg_l, segs);
750 + } else {
751 + seg_f = CONS(MAKE_INT(attr), MAKE_STR(former.c_str()));
752 + seg_c = CONS(MAKE_INT(UPreeditAttr_Cursor), MAKE_STR(""));
753 + seg_l = CONS(MAKE_INT(attr), MAKE_STR(latter.c_str()));
754 +
755 + segs = CONS(seg_f, segs);
756 + segs = CONS(seg_c, segs);
757 + segs = CONS(seg_l, segs);
758 + }
759 +
760 + return segs;
761 +}
762 +
763 +static uim_lisp
764 +compose_preedit(const commands::Output *output)
765 +{
766 + const commands::Preedit &preedit = output->preedit();
767 + uim_lisp segs = uim_scm_null();
768 + uim_lisp separator = uim_scm_callf("mozc-separator", "");
769 + int cursorPos;
770 + int count = 0;
771 + int seg_count = preedit.segment_size();
772 +
773 + cursorPos = output->preedit().cursor();
774 +
775 + for (int i = 0; i < seg_count; ++i) {
776 + const commands::Preedit::Segment segment = preedit.segment(i);
777 + const char *str = segment.value().c_str();
778 + int attr;
779 + int prev_count = count;
780 + uim_lisp seg;
781 + count += segment.value_length();
782 +
783 + switch (segment.annotation()) {
784 + case commands::Preedit::Segment::NONE:
785 + attr = UPreeditAttr_None;
786 + break;
787 + case commands::Preedit::Segment::UNDERLINE:
788 + attr = UPreeditAttr_UnderLine;
789 + break;
790 + case commands::Preedit::Segment::HIGHLIGHT:
791 + attr = UPreeditAttr_Reverse | UPreeditAttr_Cursor;
792 + break;
793 + default:
794 + attr = UPreeditAttr_None;
795 + break;
796 + }
797 +
798 + if (((prev_count < cursorPos) && (count > cursorPos)) || cursorPos == 0) {
799 + uim_lisp new_segs;
800 + if ((new_segs = insert_cursor(segs, segment, attr, cursorPos - prev_count)) != uim_scm_null()) {
801 + segs = new_segs;
802 + continue;
803 + }
804 + }
805 +
806 + seg = CONS(MAKE_INT(attr), MAKE_STR(str));
807 +
808 + if (TRUEP(separator) && i > 0)
809 + segs = CONS(separator, segs);
810 + segs = CONS(seg, segs);
811 +
812 + if (count == cursorPos && !output->preedit().has_highlighted_position()) {
813 + seg = CONS(MAKE_INT(UPreeditAttr_Cursor), MAKE_STR(""));
814 + segs = CONS(seg, segs);
815 + }
816 + }
817 +
818 + return uim_scm_callf("reverse", "o", segs);
819 +}
820 +
821 +static void
822 +update_preedit(uim_lisp mc_, int id)
823 +{
824 + uim_lisp preedit;
825 + commands::Output *output = context_slot[id].output;
826 +
827 + if (!output->has_preedit()) {
828 + if (context_slot[id].has_preedit_before) {
829 + uim_scm_callf("context-update-preedit", "oo", mc_, uim_scm_null());
830 + }
831 + context_slot[id].has_preedit_before = false;
832 +
833 + return;
834 + } else {
835 + preedit = compose_preedit(output);
836 + context_slot[id].has_preedit_before = true;
837 + }
838 + uim_scm_callf("context-update-preedit", "oo", mc_, preedit);
839 +}
840 +
841 +static void
842 +update_candidates(uim_lisp mc_, int id)
843 +{
844 + commands::Output *output = context_slot[id].output;
845 +
846 + if (!output->has_candidates()) {
847 + uim_scm_callf("im-deactivate-candidate-selector", "o", mc_);
848 + context_slot[id].cand_nr_before = 0;
849 +
850 + return;
851 + }
852 +
853 + const commands::Candidates &candidates = output->candidates();
854 + bool first_time = false;
855 +
856 + if ((context_slot[id].cand_nr_before != candidates.size()) || !candidates.focused_index())
857 + first_time = true;
858 +
859 + if (first_time)
860 + uim_scm_callf("im-activate-candidate-selector", "oii", mc_, candidates.size(), 9);
861 +
862 + if (candidates.has_focused_index()) {
863 + int index = candidates.focused_index();
864 + uim_scm_callf("im-select-candidate", "oi", mc_, index);
865 + }
866 + context_slot[id].cand_nr_before = candidates.size();
867 +
868 +#if USE_CASCADING_CANDIDATES
869 + if (first_time || (candidates.has_focused_index() && candidates.focused_index() % 9 == 0)) {
870 + context_slot[id].unique_candidate_ids->clear();
871 + for (int i = 0; i < candidates.candidate_size(); ++i) {
872 + if (candidates.candidate(i).has_id()) {
873 + const int32 cand_id = candidates.candidate(i).id();
874 + context_slot[id].unique_candidate_ids->push_back(cand_id);
875 + } else {
876 + // The parent node of the cascading window does not have an id since the
877 + // node does not contain a candidate word.
878 + context_slot[id].unique_candidate_ids->push_back(kBadCandidateId);
879 + }
880 + }
881 + }
882 +#endif
883 +}
884 +
885 +static void
886 +update_composition_mode(uim_lisp mc_, int id)
887 +{
888 + commands::Output *output = context_slot[id].output;
889 +
890 + if (!output->has_mode())
891 + return;
892 +
893 + const commands::CompositionMode newMode = output->mode();
894 + if (context_slot[id].currentMode == newMode)
895 + return;
896 +
897 + context_slot[id].currentMode = newMode;
898 +}
899 +
900 +static void
901 +update_all(uim_lisp mc_, int id)
902 +{
903 + update_result(mc_, id);
904 + update_preedit(mc_, id);
905 + update_candidates(mc_, id);
906 + update_composition_mode(mc_, id);
907 +}
908 +
909 +static uim_lisp
910 +create_context(uim_lisp mc_)
911 +{
912 + int id;
913 +
914 + client::SessionInterface *session = new client::Session;
915 + commands::Output *output = new commands::Output;
916 + if (!keyTranslator)
917 + keyTranslator = new KeyTranslator;
918 +
919 + id = unused_context_id();
920 + context_slot[id].session = session;
921 + context_slot[id].output = output;
922 + context_slot[id].currentMode = commands::HIRAGANA;
923 + context_slot[id].has_preedit_before = false;
924 + context_slot[id].cand_nr_before = 0;
925 +#if USE_CASCADING_CANDIDATES
926 + context_slot[id].unique_candidate_ids = new vector<int32>;
927 +#endif
928 +
929 + // Launch mozc_server
930 + // or should I call this with mozc-on-key?
931 + session->EnsureConnection();
932 +#if !USE_CASCADING_CANDIDATES
933 + session->EnableCascadingWindow(false);
934 +#endif
935 +
936 + return MAKE_INT(id);
937 +}
938 +
939 +static uim_lisp
940 +release_context(uim_lisp id_)
941 +{
942 + int id = C_INT(id_);
943 +
944 + if (id < nr_contexts) {
945 + SyncData(id, true);
946 + delete context_slot[id].session;
947 + delete context_slot[id].output;
948 +#if USE_CASCADING_CANDIDATES
949 + delete context_slot[id].unique_candidate_ids;
950 +#endif
951 + context_slot[id].session = NULL;
952 + context_slot[id].output = NULL;
953 + }
954 +
955 + return uim_scm_f();
956 +}
957 +
958 +static uim_lisp
959 +reset_context(uim_lisp id_)
960 +{
961 + return uim_scm_t();
962 +}
963 +
964 +static uim_lisp
965 +press_key(uim_lisp mc_, uim_lisp id_, uim_lisp key_, uim_lisp state_)
966 +{
967 + client::SessionInterface *session;
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 + preedit_method = context_slot[id].preedit_method;
978 + keyboard = uim_scm_symbol_value_str("mozc-keyboard-type-for-kana-input-method");
979 + layout_is_jp = keyboard && !strcmp(keyboard, "jp-keyboard") ? true : false;
980 + free(keyboard);
981 +
982 + keyval = C_INT(key_);
983 + modifiers = C_INT(state_);
984 + keycode = 0; /* XXX */
985 +
986 + if (!(*keyTranslator).Translate(keyval, keycode, modifiers, preedit_method, layout_is_jp, &key))
987 + return uim_scm_f();
988 +
989 + if (!(*session).SendKey(key, context_slot[id].output))
990 + return uim_scm_f();
991 +
992 + update_all(mc_, id);
993 +
994 + const bool consumed = context_slot[id].output->consumed();
995 +#if 0
996 + fprintf(stderr, "debugstring %s\n", output.DebugString().c_str());
997 + fprintf(stderr, "consumed %d\n", consumed ? 1 : 0);
998 +#endif
999 +
1000 + return consumed ? uim_scm_t() : uim_scm_f();
1001 +}
1002 +
1003 +static uim_lisp
1004 +release_key(uim_lisp id_, uim_lisp key_, uim_lisp state_)
1005 +{
1006 + return uim_scm_f();
1007 +}
1008 +
1009 +static uim_lisp
1010 +get_nr_candidates(uim_lisp id_)
1011 +{
1012 + int id = C_INT(id_);
1013 + commands::Output *output = context_slot[id].output;
1014 +
1015 + return MAKE_INT(output->candidates().size());
1016 +}
1017 +
1018 +static uim_lisp
1019 +get_nth_candidate(uim_lisp id_, uim_lisp nth_)
1020 +{
1021 + int id = C_INT(id_);
1022 + commands::Output *output = context_slot[id].output;
1023 + const commands::Candidates &candidates = output->candidates();
1024 + const char *cand;
1025 +
1026 + int nth;
1027 + int idx;
1028 + int nr;
1029 +
1030 + nth = C_INT(nth_);
1031 + nr = candidates.size();
1032 +
1033 + if (nth < nr) {
1034 + idx = nth % 9;
1035 + cand = candidates.candidate(idx).value().c_str();
1036 + } else
1037 + cand = "";
1038 +
1039 + return MAKE_STR(cand);
1040 +}
1041 +
1042 +static uim_lisp
1043 +get_nth_label(uim_lisp id_, uim_lisp nth_)
1044 +{
1045 + int id = C_INT(id_);
1046 + commands::Output *output = context_slot[id].output;
1047 + const commands::Candidates &candidates = output->candidates();
1048 + const char *label;
1049 +
1050 + int nth;
1051 + int idx;
1052 + int nr;
1053 +
1054 + nth = C_INT(nth_);
1055 + nr = candidates.size();
1056 +
1057 + if (nth < nr) {
1058 + idx = nth % 9;
1059 + label = candidates.candidate(idx).annotation().shortcut().c_str();
1060 + } else
1061 + label = "";
1062 +
1063 + return MAKE_STR(label);
1064 +}
1065 +
1066 +static uim_lisp
1067 +get_nth_annotation(uim_lisp id_, uim_lisp nth_)
1068 +{
1069 + int id = C_INT(id_);
1070 + commands::Output *output = context_slot[id].output;
1071 + const commands::Candidates &candidates = output->candidates();
1072 + const char *annotation;
1073 +
1074 + int nth;
1075 + int idx;
1076 + int nr;
1077 +
1078 + nth = C_INT(nth_);
1079 + nr = candidates.size();
1080 +
1081 + if (nth < nr) {
1082 + idx = nth % 9;
1083 + annotation = candidates.candidate(idx).annotation().description().c_str();
1084 + } else
1085 + annotation = "";
1086 +
1087 + return MAKE_STR(annotation);
1088 +}
1089 +
1090 +/* from uim-key.c */
1091 +static struct key_entry {
1092 + int key;
1093 + const char *str;
1094 +} key_tab[] = {
1095 + {UKey_Yen, "yen"},
1096 + {UKey_Backspace, "backspace"},
1097 + {UKey_Delete, "delete"},
1098 + {UKey_Escape, "escape"},
1099 + {UKey_Return, "return"},
1100 + {UKey_Tab, "tab"},
1101 + {UKey_Left, "left"},
1102 + {UKey_Up, "up"},
1103 + {UKey_Right, "right"},
1104 + {UKey_Down, "down"},
1105 + {UKey_Prior, "prior"},
1106 + {UKey_Next, "next"},
1107 + {UKey_Home, "home"},
1108 + {UKey_End, "end"},
1109 + {UKey_Insert, "insert"},
1110 + {UKey_Multi_key, "Multi_key"},
1111 + {UKey_Codeinput, "codeinput"},
1112 + {UKey_SingleCandidate, "single-candidate"},
1113 + {UKey_MultipleCandidate, "multiple-candidate"},
1114 + {UKey_PreviousCandidate, "previous-candidate"},
1115 + {UKey_Mode_switch, "Mode_switch"},
1116 + {UKey_Kanji, "Kanji"},
1117 + {UKey_Muhenkan, "Muhenkan"},
1118 + {UKey_Henkan_Mode, "Henkan_Mode"},
1119 + {UKey_Romaji, "romaji"},
1120 + {UKey_Hiragana, "hiragana"},
1121 + {UKey_Katakana, "katakana"},
1122 + {UKey_Hiragana_Katakana, "hiragana-katakana"},
1123 + {UKey_Zenkaku, "zenkaku"},
1124 + {UKey_Hankaku, "hankaku"},
1125 + {UKey_Zenkaku_Hankaku, "zenkaku-hankaku"},
1126 + {UKey_Touroku, "touroku"},
1127 + {UKey_Massyo, "massyo"},
1128 + {UKey_Kana_Lock, "kana-lock"},
1129 + {UKey_Kana_Shift, "kana-shift"},
1130 + {UKey_Eisu_Shift, "eisu-shift"},
1131 + {UKey_Eisu_toggle, "eisu-toggle"},
1132 +
1133 + {UKey_Hangul, "hangul"},
1134 + {UKey_Hangul_Start, "hangul-start"},
1135 + {UKey_Hangul_End, "hangul-end"},
1136 + {UKey_Hangul_Hanja, "hangul-hanja"},
1137 + {UKey_Hangul_Jamo, "hangul-jamo"},
1138 + {UKey_Hangul_Romaja, "hangul-romaja"},
1139 + {UKey_Hangul_Codeinput, "hangul-codeinput"},
1140 + {UKey_Hangul_Jeonja, "hangul-jeonja"},
1141 + {UKey_Hangul_Banja, "hangul-banja"},
1142 + {UKey_Hangul_PreHanja, "hangul-prehanja"},
1143 + {UKey_Hangul_PostHanja, "hangul-posthanja"},
1144 + {UKey_Hangul_SingleCandidate, "hangul-single-candidate"},
1145 + {UKey_Hangul_MultipleCandidate, "hangul-multiple-candidate"},
1146 + {UKey_Hangul_PreviousCandidate, "hangul-previous-candidate"},
1147 + {UKey_Hangul_Special, "hangul-special"},
1148 +
1149 + {UKey_F1, "F1"},
1150 + {UKey_F2, "F2"},
1151 + {UKey_F3, "F3"},
1152 + {UKey_F4, "F4"},
1153 + {UKey_F5, "F5"},
1154 + {UKey_F6, "F6"},
1155 + {UKey_F7, "F7"},
1156 + {UKey_F8, "F8"},
1157 + {UKey_F9, "F9"},
1158 + {UKey_F10, "F10"},
1159 + {UKey_F11, "F11"},
1160 + {UKey_F12, "F12"},
1161 + {UKey_F13, "F13"},
1162 + {UKey_F14, "F14"},
1163 + {UKey_F15, "F15"},
1164 + {UKey_F16, "F16"},
1165 + {UKey_F17, "F17"},
1166 + {UKey_F18, "F18"},
1167 + {UKey_F19, "F19"},
1168 + {UKey_F20, "F20"},
1169 + {UKey_F21, "F21"},
1170 + {UKey_F22, "F22"},
1171 + {UKey_F23, "F23"},
1172 + {UKey_F24, "F24"},
1173 + {UKey_F25, "F25"},
1174 + {UKey_F26, "F26"},
1175 + {UKey_F27, "F27"},
1176 + {UKey_F28, "F28"},
1177 + {UKey_F29, "F29"},
1178 + {UKey_F30, "F30"},
1179 + {UKey_F31, "F31"},
1180 + {UKey_F32, "F32"},
1181 + {UKey_F33, "F33"},
1182 + {UKey_F34, "F34"},
1183 + {UKey_F35, "F35"},
1184 +
1185 + {UKey_Dead_Grave, "dead-grave"},
1186 + {UKey_Dead_Acute, "dead-acute"},
1187 + {UKey_Dead_Circumflex, "dead-circumflex"},
1188 + {UKey_Dead_Tilde, "dead-tilde"},
1189 + {UKey_Dead_Macron, "dead-macron"},
1190 + {UKey_Dead_Breve, "dead-breve"},
1191 + {UKey_Dead_Abovedot, "dead-abovedot"},
1192 + {UKey_Dead_Diaeresis, "dead-diaeresis"},
1193 + {UKey_Dead_Abovering, "dead-abovering"},
1194 + {UKey_Dead_Doubleacute, "dead-doubleacute"},
1195 + {UKey_Dead_Caron, "dead-caron"},
1196 + {UKey_Dead_Cedilla, "dead-cedilla"},
1197 + {UKey_Dead_Ogonek, "dead-ogonek"},
1198 + {UKey_Dead_Iota, "dead-iota"},
1199 + {UKey_Dead_VoicedSound, "dead-voiced-sound"},
1200 + {UKey_Dead_SemivoicedSound, "dead-semivoiced-sound"},
1201 + {UKey_Dead_Belowdot, "dead-belowdot"},
1202 + {UKey_Dead_Hook, "dead-hook"},
1203 + {UKey_Dead_Horn, "dead-horn"},
1204 +
1205 + {UKey_Kana_Fullstop, "kana-fullstop"},
1206 + {UKey_Kana_OpeningBracket, "kana-opening-bracket"},
1207 + {UKey_Kana_ClosingBracket, "kana-closing-bracket"},
1208 + {UKey_Kana_Comma, "kana-comma"},
1209 + {UKey_Kana_Conjunctive, "kana-conjunctive"},
1210 + {UKey_Kana_WO, "kana-WO"},
1211 + {UKey_Kana_a, "kana-a"},
1212 + {UKey_Kana_i, "kana-i"},
1213 + {UKey_Kana_u, "kana-u"},
1214 + {UKey_Kana_e, "kana-e"},
1215 + {UKey_Kana_o, "kana-o"},
1216 + {UKey_Kana_ya, "kana-ya"},
1217 + {UKey_Kana_yu, "kana-yu"},
1218 + {UKey_Kana_yo, "kana-yo"},
1219 + {UKey_Kana_tsu, "kana-tsu"},
1220 + {UKey_Kana_ProlongedSound, "kana-prolonged-sound"},
1221 + {UKey_Kana_A, "kana-A"},
1222 + {UKey_Kana_I, "kana-I"},
1223 + {UKey_Kana_U, "kana-U"},
1224 + {UKey_Kana_E, "kana-E"},
1225 + {UKey_Kana_O, "kana-O"},
1226 + {UKey_Kana_KA, "kana-KA"},
1227 + {UKey_Kana_KI, "kana-KI"},
1228 + {UKey_Kana_KU, "kana-KU"},
1229 + {UKey_Kana_KE, "kana-KE"},
1230 + {UKey_Kana_KO, "kana-KO"},
1231 + {UKey_Kana_SA, "kana-SA"},
1232 + {UKey_Kana_SHI, "kana-SHI"},
1233 + {UKey_Kana_SU, "kana-SU"},
1234 + {UKey_Kana_SE, "kana-SE"},
1235 + {UKey_Kana_SO, "kana-SO"},
1236 + {UKey_Kana_TA, "kana-TA"},
1237 + {UKey_Kana_CHI, "kana-CHI"},
1238 + {UKey_Kana_TSU, "kana-TSU"},
1239 + {UKey_Kana_TE, "kana-TE"},
1240 + {UKey_Kana_TO, "kana-TO"},
1241 + {UKey_Kana_NA, "kana-NA"},
1242 + {UKey_Kana_NI, "kana-NI"},
1243 + {UKey_Kana_NU, "kana-NU"},
1244 + {UKey_Kana_NE, "kana-NE"},
1245 + {UKey_Kana_NO, "kana-NO"},
1246 + {UKey_Kana_HA, "kana-HA"},
1247 + {UKey_Kana_HI, "kana-HI"},
1248 + {UKey_Kana_FU, "kana-FU"},
1249 + {UKey_Kana_HE, "kana-HE"},
1250 + {UKey_Kana_HO, "kana-HO"},
1251 + {UKey_Kana_MA, "kana-MA"},
1252 + {UKey_Kana_MI, "kana-MI"},
1253 + {UKey_Kana_MU, "kana-MU"},
1254 + {UKey_Kana_ME, "kana-ME"},
1255 + {UKey_Kana_MO, "kana-MO"},
1256 + {UKey_Kana_YA, "kana-YA"},
1257 + {UKey_Kana_YU, "kana-YU"},
1258 + {UKey_Kana_YO, "kana-YO"},
1259 + {UKey_Kana_RA, "kana-RA"},
1260 + {UKey_Kana_RI, "kana-RI"},
1261 + {UKey_Kana_RU, "kana-RU"},
1262 + {UKey_Kana_RE, "kana-RE"},
1263 + {UKey_Kana_RO, "kana-RO"},
1264 + {UKey_Kana_WA, "kana-WA"},
1265 + {UKey_Kana_N, "kana-N"},
1266 + {UKey_Kana_VoicedSound, "kana-voiced-sound"},
1267 + {UKey_Kana_SemivoicedSound, "kana-semivoiced-sound"},
1268 +
1269 + {UKey_Private1, "Private1"},
1270 + {UKey_Private2, "Private2"},
1271 + {UKey_Private3, "Private3"},
1272 + {UKey_Private4, "Private4"},
1273 + {UKey_Private5, "Private5"},
1274 + {UKey_Private6, "Private6"},
1275 + {UKey_Private7, "Private7"},
1276 + {UKey_Private8, "Private8"},
1277 + {UKey_Private9, "Private9"},
1278 + {UKey_Private10, "Private10"},
1279 + {UKey_Private11, "Private11"},
1280 + {UKey_Private12, "Private12"},
1281 + {UKey_Private13, "Private13"},
1282 + {UKey_Private14, "Private14"},
1283 + {UKey_Private15, "Private15"},
1284 + {UKey_Private16, "Private16"},
1285 + {UKey_Private17, "Private17"},
1286 + {UKey_Private18, "Private18"},
1287 + {UKey_Private19, "Private19"},
1288 + {UKey_Private20, "Private20"},
1289 + {UKey_Private21, "Private21"},
1290 + {UKey_Private22, "Private22"},
1291 + {UKey_Private23, "Private23"},
1292 + {UKey_Private24, "Private24"},
1293 + {UKey_Private25, "Private25"},
1294 + {UKey_Private26, "Private26"},
1295 + {UKey_Private27, "Private27"},
1296 + {UKey_Private28, "Private28"},
1297 + {UKey_Private29, "Private29"},
1298 + {UKey_Private30, "Private30"},
1299 + {UKey_Shift_key, "Shift_key"},
1300 + {UKey_Alt_key, "Alt_key"},
1301 + {UKey_Control_key, "Control_key"},
1302 + {UKey_Meta_key, "Meta_key"},
1303 + {UKey_Super_key, "Super_key"},
1304 + {UKey_Hyper_key, "Hyper_key"},
1305 +
1306 + {UKey_Caps_Lock, "caps-lock"},
1307 + {UKey_Num_Lock, "num-lock"},
1308 + {UKey_Scroll_Lock, "scroll-lock"},
1309 + /* {UKey_Other, "other"},*/
1310 + {0, 0}
1311 +};
1312 +
1313 +struct eqstr
1314 +{
1315 + bool operator()(const char* s1, const char* s2) const
1316 + {
1317 + return strcmp(s1, s2) == 0;
1318 + }
1319 +};
1320 +
1321 +typedef hash_map<const char *, int, __gnu_cxx::hash<const char *>, eqstr> KeyMap;
1322 +static KeyMap key_map;
1323 +
1324 +static void install_keymap(void)
1325 +{
1326 + int i;
1327 +
1328 + for (i = 0; key_tab[i].key; i++)
1329 + key_map.insert(make_pair(key_tab[i].str, key_tab[i].key));
1330 +}
1331 +
1332 +static uim_lisp
1333 +keysym_to_int(uim_lisp sym_)
1334 +{
1335 + const char *sym = uim_scm_refer_c_str(sym_);
1336 + int key = 0;
1337 +
1338 + KeyMap::iterator it = key_map.find(sym);
1339 + if (it != key_map.end())
1340 + key = it->second;
1341 +
1342 + return uim_scm_make_int(key);
1343 +}
1344 +
1345 +static uim_lisp
1346 +get_composition_mode(uim_lisp id_)
1347 +{
1348 + int id = C_INT(id_);
1349 + const commands::CompositionMode mode = context_slot[id].currentMode;
1350 + int type = 0;
1351 +
1352 + switch (mode) {
1353 + case commands::DIRECT:
1354 + type = -1;
1355 + break;
1356 + case commands::HIRAGANA:
1357 + type = 0;
1358 + break;
1359 + case commands::FULL_KATAKANA:
1360 + type = 1;
1361 + break;
1362 + case commands::HALF_KATAKANA:
1363 + type = 2;
1364 + break;
1365 + case commands::HALF_ASCII:
1366 + type = 3;
1367 + break;
1368 + case commands::FULL_ASCII:
1369 + type = 4;
1370 + break;
1371 + default:
1372 + type = -1;
1373 + break;
1374 + }
1375 +
1376 + return MAKE_INT(type);
1377 +}
1378 +
1379 +static uim_lisp
1380 +set_composition_mode(uim_lisp mc_, uim_lisp id_, uim_lisp new_mode_)
1381 +{
1382 + int id = C_INT(id_);
1383 + commands::CompositionMode mode;
1384 + commands::SessionCommand command;
1385 +
1386 + switch (C_INT(new_mode_)) {
1387 + case -1:
1388 + mode = commands::DIRECT;
1389 + break;
1390 + case 0:
1391 + mode = commands::HIRAGANA;
1392 + break;
1393 + case 1:
1394 + mode = commands::FULL_KATAKANA;
1395 + break;
1396 + case 2:
1397 + mode = commands::HALF_KATAKANA;
1398 + break;
1399 + case 3:
1400 + mode = commands::HALF_ASCII;
1401 + break;
1402 + case 4:
1403 + mode = commands::FULL_ASCII;
1404 + break;
1405 + default:
1406 + mode = commands::HIRAGANA;
1407 + break;
1408 + }
1409 +
1410 + if (mode == commands::DIRECT) {
1411 + command.set_type(commands::SessionCommand::SUBMIT);
1412 + context_slot[id].session->SendCommand(command, context_slot[id].output);
1413 + update_all(mc_, id);
1414 + uim_scm_callf("mozc-context-set-on!", "oo", mc_, uim_scm_f());
1415 + } else {
1416 + command.set_type(commands::SessionCommand::SWITCH_INPUT_MODE);
1417 + command.set_composition_mode(mode);
1418 + context_slot[id].session->SendCommand(command, context_slot[id].output);
1419 + context_slot[id].currentMode = mode; /* don't set this with DIRECT mode */
1420 + uim_scm_callf("mozc-context-set-on!", "oo", mc_, uim_scm_t());
1421 + }
1422 +
1423 + return uim_scm_t();
1424 +}
1425 +
1426 +static uim_lisp
1427 +set_composition_on(uim_lisp id_)
1428 +{
1429 + int id = C_INT(id_);
1430 + commands::SessionCommand command;
1431 +
1432 + command.set_type(commands::SessionCommand::SWITCH_INPUT_MODE);
1433 + command.set_composition_mode(context_slot[id].currentMode);
1434 + context_slot[id].session->SendCommand(command, context_slot[id].output);
1435 +
1436 + return uim_scm_t();
1437 +}
1438 +
1439 +static uim_lisp
1440 +has_preedit(uim_lisp id_)
1441 +{
1442 + int id = C_INT(id_);
1443 +
1444 + return context_slot[id].has_preedit_before ? uim_scm_t() : uim_scm_f();
1445 +}
1446 +
1447 +static uim_lisp
1448 +select_candidate(uim_lisp mc_, uim_lisp id_, uim_lisp idx_)
1449 +{
1450 + int id = C_INT(id_);
1451 + int idx = C_INT(idx_) % 9;
1452 +
1453 +#if USE_CASCADING_CANDIDATES
1454 + if (idx >= context_slot[id].unique_candidate_ids->size())
1455 +#else
1456 + if (idx >= context_slot[id].output->candidates().candidate_size())
1457 +#endif
1458 + return uim_scm_f();
1459 +
1460 +#if USE_CASCADING_CANDIDATES
1461 + const int32 cand_id = (*context_slot[id].unique_candidate_ids)[idx];
1462 + if (cand_id == kBadCandidateId)
1463 + return uim_scm_f();
1464 +#else
1465 + const int32 cand_id = context_slot[id].output->candidates().candidate(idx).id();
1466 +#endif
1467 +
1468 + commands::Output output;
1469 + commands::SessionCommand command;
1470 + command.set_type(commands::SessionCommand::SELECT_CANDIDATE);
1471 + command.set_id(cand_id);
1472 + context_slot[id].session->SendCommand(command, context_slot[id].output);
1473 + update_all(mc_, id);
1474 +
1475 + return uim_scm_t();
1476 +}
1477 +
1478 +static uim_lisp
1479 +get_input_rule(uim_lisp id_)
1480 +{
1481 + int id = C_INT(id_);
1482 + const config::Config::PreeditMethod method = context_slot[id].preedit_method;
1483 + int rule = 0;
1484 +
1485 + switch (method) {
1486 + case config::Config::ROMAN:
1487 + rule = 0;
1488 + break;
1489 + case config::Config::KANA:
1490 + rule = 1;
1491 + break;
1492 + default:
1493 + rule = 0;
1494 + break;
1495 + }
1496 +
1497 + return MAKE_INT(rule);
1498 +}
1499 +
1500 +static uim_lisp
1501 +set_input_rule(uim_lisp mc_, uim_lisp id_, uim_lisp new_rule_)
1502 +{
1503 + int id = C_INT(id_);
1504 + config::Config config;
1505 + config::Config::PreeditMethod method;
1506 +
1507 + switch (C_INT(new_rule_)) {
1508 + case 0:
1509 + method = config::Config::ROMAN;
1510 + break;
1511 + case 1:
1512 + method = config::Config::KANA;
1513 + break;
1514 + default:
1515 + method = config::Config::ROMAN;
1516 + break;
1517 + }
1518 +
1519 + if (!context_slot[id].session->GetConfig(&config))
1520 + return false;
1521 +
1522 + config.set_preedit_method(method);
1523 +
1524 + if (!context_slot[id].session->SetConfig(config))
1525 + return false;
1526 +
1527 + context_slot[id].preedit_method = method;
1528 +
1529 + return uim_scm_t();
1530 +}
1531 +
1532 +} // namespace
1533 +} // namespace
1534 +
1535 +
1536 +
1537 +void
1538 +uim_plugin_instance_init(void)
1539 +{
1540 + uim_scm_init_proc1("mozc-lib-alloc-context", mozc::uim::create_context);
1541 + uim_scm_init_proc1("mozc-lib-free-context", mozc::uim::release_context);
1542 + uim_scm_init_proc1("mozc-lib-reset", mozc::uim::reset_context);
1543 + uim_scm_init_proc4("mozc-lib-press-key", mozc::uim::press_key);
1544 + uim_scm_init_proc3("mozc-lib-release-key", mozc::uim::release_key);
1545 + uim_scm_init_proc1("mozc-lib-get-nr-candidates", mozc::uim::get_nr_candidates);
1546 + uim_scm_init_proc2("mozc-lib-get-nth-candidate", mozc::uim::get_nth_candidate);
1547 + uim_scm_init_proc2("mozc-lib-get-nth-label", mozc::uim::get_nth_label);
1548 + uim_scm_init_proc2("mozc-lib-get-nth-annotation", mozc::uim::get_nth_annotation);
1549 + uim_scm_init_proc1("keysym-to-int", mozc::uim::keysym_to_int);
1550 + uim_scm_init_proc1("mozc-lib-input-mode", mozc::uim::get_composition_mode);
1551 + uim_scm_init_proc3("mozc-lib-set-input-mode", mozc::uim::set_composition_mode);
1552 + uim_scm_init_proc1("mozc-lib-set-on", mozc::uim::set_composition_on);
1553 + uim_scm_init_proc1("mozc-lib-has-preedit?", mozc::uim::has_preedit);
1554 + uim_scm_init_proc3("mozc-lib-set-candidate-index", mozc::uim::select_candidate);
1555 + uim_scm_init_proc1("mozc-lib-input-rule", mozc::uim::get_input_rule);
1556 + uim_scm_init_proc3("mozc-lib-set-input-rule", mozc::uim::set_input_rule);
1557 +
1558 + int argc = 1;
1559 + static const char name[] = "uim-mozc";
1560 + argv = (char **)malloc(sizeof(char *) * 2);
1561 + argv[0] = (char *)name;
1562 + argv[1] = NULL;
1563 +
1564 + InitGoogle((const char *)argv[0], &argc, (char ***)&argv, true);
1565 + mozc::uim::install_keymap();
1566 +}
1567 +
1568 +void
1569 +uim_plugin_instance_quit(void)
1570 +{
1571 + mozc::uim::key_map.clear();
1572 + for (int i = 0; i < mozc::uim::nr_contexts; i++) {
1573 + if (mozc::uim::context_slot[i].session) {
1574 + delete mozc::uim::context_slot[i].session;
1575 + delete mozc::uim::context_slot[i].output;
1576 + }
1577 + }
1578 + delete mozc::uim::keyTranslator;
1579 + mozc::uim::keyTranslator = NULL;
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
00 0001-Add-support-kfreebsd.patch
1 0002-Add-uim-mozc-r204.patch
2 mozc-el-pseudo-cursor.patch
1 uim-mozc.patch
2 # mozc-el-pseudo-cursor.patch
33 # mozc-el-not-suggest-in-minibuffer-fixed.patch
44 add_file_to_gypfile_check.patch
0 From 02ae723697b09c3cf86d0d4595849bc2f3e0fe3f Mon Sep 17 00:00:00 2001
1 From: Nobuhiro Iwamatsu <iwamatsu@debian.org>
2 Date: Tue, 15 Mar 2011 01:04:04 +0900
3 Subject: [PATCH] Add uim-mozc r222
4
5 Signed-off-by: Nobuhiro Iwamatsu <iwamatsu@debian.org>
6 ---
7 unix/uim/key_translator.cc | 436 +++++++++++++++++
8 unix/uim/key_translator.h | 111 +++++
9 unix/uim/mozc.cc | 992 ++++++++++++++++++++++++++++++++++++++
10 unix/uim/scm/mozc-custom.scm | 259 ++++++++++
11 unix/uim/scm/mozc-key-custom.scm | 74 +++
12 unix/uim/scm/mozc.scm | 352 ++++++++++++++
13 unix/uim/uim.gyp | 82 ++++
14 7 files changed, 2306 insertions(+), 0 deletions(-)
15 create mode 100644 unix/uim/key_translator.cc
16 create mode 100644 unix/uim/key_translator.h
17 create mode 100644 unix/uim/mozc.cc
18 create mode 100644 unix/uim/scm/mozc-custom.scm
19 create mode 100644 unix/uim/scm/mozc-key-custom.scm
20 create mode 100644 unix/uim/scm/mozc.scm
21 create mode 100644 unix/uim/uim.gyp
22
23 diff --git a/unix/uim/key_translator.cc b/unix/uim/key_translator.cc
24 new file mode 100644
25 index 0000000..ae1cd2d
26 --- /dev/null
27 +++ b/unix/uim/key_translator.cc
28 @@ -0,0 +1,436 @@
29 +// Copyright 2010, Google Inc.
30 +// Copyright (c) 2010 uim Project http://code.google.com/p/uim/
31 +// All rights reserved.
32 +//
33 +// Redistribution and use in source and binary forms, with or without
34 +// modification, are permitted provided that the following conditions are
35 +// met:
36 +//
37 +// * Redistributions of source code must retain the above copyright
38 +// notice, this list of conditions and the following disclaimer.
39 +// * Redistributions in binary form must reproduce the above
40 +// copyright notice, this list of conditions and the following disclaimer
41 +// in the documentation and/or other materials provided with the
42 +// distribution.
43 +// * Neither the name of authors nor the names of its
44 +// contributors may be used to endorse or promote products derived from
45 +// this software without specific prior written permission.
46 +//
47 +// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
48 +// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
49 +// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
50 +// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
51 +// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
52 +// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
53 +// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
54 +// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
55 +// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
56 +// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
57 +// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
58 +
59 +#include "unix/uim/key_translator.h"
60 +
61 +#include <uim.h>
62 +
63 +#include "base/logging.h"
64 +
65 +namespace {
66 +
67 +const struct SpecialKeyMap {
68 + unsigned int from;
69 + mozc::commands::KeyEvent::SpecialKey to;
70 +} special_key_map[] = {
71 + {0x20, mozc::commands::KeyEvent::SPACE},
72 + {UKey_Return, mozc::commands::KeyEvent::ENTER},
73 + {UKey_Left, mozc::commands::KeyEvent::LEFT},
74 + {UKey_Right, mozc::commands::KeyEvent::RIGHT},
75 + {UKey_Up, mozc::commands::KeyEvent::UP},
76 + {UKey_Down, mozc::commands::KeyEvent::DOWN},
77 + {UKey_Escape, mozc::commands::KeyEvent::ESCAPE},
78 + {UKey_Delete, mozc::commands::KeyEvent::DEL},
79 + {UKey_Backspace, mozc::commands::KeyEvent::BACKSPACE},
80 + {UKey_Insert, mozc::commands::KeyEvent::INSERT},
81 + {UKey_Henkan, mozc::commands::KeyEvent::HENKAN},
82 + {UKey_Muhenkan, mozc::commands::KeyEvent::MUHENKAN},
83 + {UKey_Hiragana, mozc::commands::KeyEvent::KANA},
84 + {UKey_Katakana, mozc::commands::KeyEvent::KANA},
85 + {UKey_Eisu_toggle, mozc::commands::KeyEvent::EISU},
86 + {UKey_Home, mozc::commands::KeyEvent::HOME},
87 + {UKey_End, mozc::commands::KeyEvent::END},
88 + {UKey_Tab, mozc::commands::KeyEvent::TAB},
89 + {UKey_F1, mozc::commands::KeyEvent::F1},
90 + {UKey_F2, mozc::commands::KeyEvent::F2},
91 + {UKey_F3, mozc::commands::KeyEvent::F3},
92 + {UKey_F4, mozc::commands::KeyEvent::F4},
93 + {UKey_F5, mozc::commands::KeyEvent::F5},
94 + {UKey_F6, mozc::commands::KeyEvent::F6},
95 + {UKey_F7, mozc::commands::KeyEvent::F7},
96 + {UKey_F8, mozc::commands::KeyEvent::F8},
97 + {UKey_F9, mozc::commands::KeyEvent::F9},
98 + {UKey_F10, mozc::commands::KeyEvent::F10},
99 + {UKey_F11, mozc::commands::KeyEvent::F11},
100 + {UKey_F12, mozc::commands::KeyEvent::F12},
101 + {UKey_F13, mozc::commands::KeyEvent::F13},
102 + {UKey_F14, mozc::commands::KeyEvent::F14},
103 + {UKey_F15, mozc::commands::KeyEvent::F15},
104 + {UKey_F16, mozc::commands::KeyEvent::F16},
105 + {UKey_F17, mozc::commands::KeyEvent::F17},
106 + {UKey_F18, mozc::commands::KeyEvent::F18},
107 + {UKey_F19, mozc::commands::KeyEvent::F19},
108 + {UKey_F20, mozc::commands::KeyEvent::F20},
109 + {UKey_F21, mozc::commands::KeyEvent::F21},
110 + {UKey_F22, mozc::commands::KeyEvent::F22},
111 + {UKey_F23, mozc::commands::KeyEvent::F23},
112 + {UKey_F24, mozc::commands::KeyEvent::F24},
113 + {UKey_Prior, mozc::commands::KeyEvent::PAGE_UP},
114 + {UKey_Next, mozc::commands::KeyEvent::PAGE_DOWN},
115 +};
116 +
117 +const struct ModifierKeyMap {
118 + unsigned int from;
119 + mozc::commands::KeyEvent::ModifierKey to;
120 +} modifier_key_map[] = {
121 + {UKey_Shift, mozc::commands::KeyEvent::SHIFT},
122 + {UKey_Control, mozc::commands::KeyEvent::CTRL},
123 + {UKey_Alt, mozc::commands::KeyEvent::ALT},
124 +};
125 +
126 +const struct ModifierMaskMap {
127 + unsigned int from;
128 + mozc::commands::KeyEvent::ModifierKey to;
129 +} modifier_mask_map[] = {
130 + {UMod_Shift, mozc::commands::KeyEvent::SHIFT},
131 + {UMod_Control, mozc::commands::KeyEvent::CTRL},
132 + {UMod_Alt, mozc::commands::KeyEvent::ALT},
133 +};
134 +
135 +// TODO:Add kana_map_dv to support Dvoraklayout.
136 +const struct KanaMap {
137 + unsigned int code;
138 + const char *no_shift;
139 + const char *shift;
140 +} kana_map_jp[] = {
141 + { '1' , "\xe3\x81\xac", "\xe3\x81\xac" }, // "ぬ", "ぬ"
142 + { '!' , "\xe3\x81\xac", "\xe3\x81\xac" }, // "ぬ", "ぬ"
143 + { '2' , "\xe3\x81\xb5", "\xe3\x81\xb5" }, // "ふ", "ふ"
144 + { '\"', "\xe3\x81\xb5", "\xe3\x81\xb5" }, // "ふ", "ふ"
145 + { '3' , "\xe3\x81\x82", "\xe3\x81\x81" }, // "あ", "ぁ"
146 + { '#' , "\xe3\x81\x81", "\xe3\x81\x81" }, // "ぁ", "ぁ"
147 + { '4' , "\xe3\x81\x86", "\xe3\x81\x85" }, // "う", "ぅ"
148 + { '$' , "\xe3\x81\x85", "\xe3\x81\x85" }, // "ぅ", "ぅ"
149 + { '5' , "\xe3\x81\x88", "\xe3\x81\x87" }, // "え", "ぇ"
150 + { '%' , "\xe3\x81\x87", "\xe3\x81\x87" }, // "ぇ", "ぇ"
151 + { '6' , "\xe3\x81\x8a", "\xe3\x81\x89" }, // "お", "ぉ"
152 + { '&' , "\xe3\x81\x89", "\xe3\x81\x89" }, // "ぉ", "ぉ"
153 + { '7' , "\xe3\x82\x84", "\xe3\x82\x83" }, // "や", "ゃ"
154 + { '\'', "\xe3\x82\x83", "\xe3\x82\x83" }, // "ゃ", "ゃ"
155 + { '8' , "\xe3\x82\x86", "\xe3\x82\x85" }, // "ゆ", "ゅ"
156 + { '(' , "\xe3\x82\x85", "\xe3\x82\x85" }, // "ゅ", "ゅ"
157 + { '9' , "\xe3\x82\x88", "\xe3\x82\x87" }, // "よ", "ょ"
158 + { ')' , "\xe3\x82\x87", "\xe3\x82\x87" }, // "ょ", "ょ"
159 + { '0' , "\xe3\x82\x8f", "\xe3\x82\x92" }, // "わ", "を"
160 + { '-' , "\xe3\x81\xbb", "\xe3\x81\xbb" }, // "ほ", "ほ"
161 + { '=' , "\xe3\x81\xbb", "\xe3\x81\xbb" }, // "ほ", "ほ"
162 + { '^' , "\xe3\x81\xb8", "\xe3\x81\xb8" }, // "へ", "へ"
163 + { '~' , "\xe3\x82\x92", "\xe3\x82\x92" }, // "を", "を"
164 + { '|' , "\xe3\x83\xbc", "\xe3\x83\xbc" }, // "ー", "ー"
165 + { 'q' , "\xe3\x81\x9f", "\xe3\x81\x9f" }, // "た", "た"
166 + { 'Q' , "\xe3\x81\x9f", "\xe3\x81\x9f" }, // "た", "た"
167 + { 'w' , "\xe3\x81\xa6", "\xe3\x81\xa6" }, // "て", "て"
168 + { 'W' , "\xe3\x81\xa6", "\xe3\x81\xa6" }, // "て", "て"
169 + { 'e' , "\xe3\x81\x84", "\xe3\x81\x83" }, // "い", "ぃ"
170 + { 'E' , "\xe3\x81\x83", "\xe3\x81\x83" }, // "ぃ", "ぃ"
171 + { 'r' , "\xe3\x81\x99", "\xe3\x81\x99" }, // "す", "す"
172 + { 'R' , "\xe3\x81\x99", "\xe3\x81\x99" }, // "す", "す"
173 + { 't' , "\xe3\x81\x8b", "\xe3\x81\x8b" }, // "か", "か"
174 + { 'T' , "\xe3\x81\x8b", "\xe3\x81\x8b" }, // "か", "か"
175 + { 'y' , "\xe3\x82\x93", "\xe3\x82\x93" }, // "ん", "ん"
176 + { 'Y' , "\xe3\x82\x93", "\xe3\x82\x93" }, // "ん", "ん"
177 + { 'u' , "\xe3\x81\xaa", "\xe3\x81\xaa" }, // "な", "な"
178 + { 'U' , "\xe3\x81\xaa", "\xe3\x81\xaa" }, // "な", "な"
179 + { 'i' , "\xe3\x81\xab", "\xe3\x81\xab" }, // "に", "に"
180 + { 'I' , "\xe3\x81\xab", "\xe3\x81\xab" }, // "に", "に"
181 + { 'o' , "\xe3\x82\x89", "\xe3\x82\x89" }, // "ら", "ら"
182 + { 'O' , "\xe3\x82\x89", "\xe3\x82\x89" }, // "ら", "ら"
183 + { 'p' , "\xe3\x81\x9b", "\xe3\x81\x9b" }, // "せ", "せ"
184 + { 'P' , "\xe3\x81\x9b", "\xe3\x81\x9b" }, // "せ", "せ"
185 + { '@' , "\xe3\x82\x9b", "\xe3\x82\x9b" }, // "゛", "゛"
186 + { '`' , "\xe3\x82\x9b", "\xe3\x82\x9b" }, // "゛", "゛"
187 + { '[' , "\xe3\x82\x9c", "\xe3\x80\x8c" }, // "゜", "「"
188 + { '{' , "\xe3\x82\x9c", "\xe3\x80\x8c" }, // "゜", "「"
189 + { 'a' , "\xe3\x81\xa1", "\xe3\x81\xa1" }, // "ち", "ち"
190 + { 'A' , "\xe3\x81\xa1", "\xe3\x81\xa1" }, // "ち", "ち"
191 + { 's' , "\xe3\x81\xa8", "\xe3\x81\xa8" }, // "と", "と"
192 + { 'S' , "\xe3\x81\xa8", "\xe3\x81\xa8" }, // "と", "と"
193 + { 'd' , "\xe3\x81\x97", "\xe3\x81\x97" }, // "し", "し"
194 + { 'D' , "\xe3\x81\x97", "\xe3\x81\x97" }, // "し", "し"
195 + { 'f' , "\xe3\x81\xaf", "\xe3\x81\xaf" }, // "は", "は"
196 + { 'F' , "\xe3\x81\xaf", "\xe3\x81\xaf" }, // "は", "は"
197 + { 'g' , "\xe3\x81\x8d", "\xe3\x81\x8d" }, // "き", "き"
198 + { 'G' , "\xe3\x81\x8d", "\xe3\x81\x8d" }, // "き", "き"
199 + { 'h' , "\xe3\x81\x8f", "\xe3\x81\x8f" }, // "く", "く"
200 + { 'H' , "\xe3\x81\x8f", "\xe3\x81\x8f" }, // "く", "く"
201 + { 'j' , "\xe3\x81\xbe", "\xe3\x81\xbe" }, // "ま", "ま"
202 + { 'J' , "\xe3\x81\xbe", "\xe3\x81\xbe" }, // "ま", "ま"
203 + { 'k' , "\xe3\x81\xae", "\xe3\x81\xae" }, // "の", "の"
204 + { 'K' , "\xe3\x81\xae", "\xe3\x81\xae" }, // "の", "の"
205 + { 'l' , "\xe3\x82\x8a", "\xe3\x82\x8a" }, // "り", "り"
206 + { 'L' , "\xe3\x82\x8a", "\xe3\x82\x8a" }, // "り", "り"
207 + { ';' , "\xe3\x82\x8c", "\xe3\x82\x8c" }, // "れ", "れ"
208 + { '+' , "\xe3\x82\x8c", "\xe3\x82\x8c" }, // "れ", "れ"
209 + { ':' , "\xe3\x81\x91", "\xe3\x81\x91" }, // "け", "け"
210 + { '*' , "\xe3\x81\x91", "\xe3\x81\x91" }, // "け", "け"
211 + { ']' , "\xe3\x82\x80", "\xe3\x80\x8d" }, // "む", "」"
212 + { '}' , "\xe3\x80\x8d", "\xe3\x80\x8d" }, // "」", "」"
213 + { 'z' , "\xe3\x81\xa4", "\xe3\x81\xa3" }, // "つ", "っ"
214 + { 'Z' , "\xe3\x81\xa3", "\xe3\x81\xa3" }, // "っ", "っ"
215 + { 'x' , "\xe3\x81\x95", "\xe3\x81\x95" }, // "さ", "さ"
216 + { 'X' , "\xe3\x81\x95", "\xe3\x81\x95" }, // "さ", "さ"
217 + { 'c' , "\xe3\x81\x9d", "\xe3\x81\x9d" }, // "そ", "そ"
218 + { 'C' , "\xe3\x81\x9d", "\xe3\x81\x9d" }, // "そ", "そ"
219 + { 'v' , "\xe3\x81\xb2", "\xe3\x81\xb2" }, // "ひ", "ひ"
220 + { 'V' , "\xe3\x81\xb2", "\xe3\x81\xb2" }, // "ひ", "ひ"
221 + { 'b' , "\xe3\x81\x93", "\xe3\x81\x93" }, // "こ", "こ"
222 + { 'B' , "\xe3\x81\x93", "\xe3\x81\x93" }, // "こ", "こ"
223 + { 'n' , "\xe3\x81\xbf", "\xe3\x81\xbf" }, // "み", "み"
224 + { 'N' , "\xe3\x81\xbf", "\xe3\x81\xbf" }, // "み", "み"
225 + { 'm' , "\xe3\x82\x82", "\xe3\x82\x82" }, // "も", "も"
226 + { 'M' , "\xe3\x82\x82", "\xe3\x82\x82" }, // "も", "も"
227 + { ',' , "\xe3\x81\xad", "\xe3\x80\x81" }, // "ね", "、"
228 + { '<' , "\xe3\x80\x81", "\xe3\x80\x81" }, // "、", "、"
229 + { '.' , "\xe3\x82\x8b", "\xe3\x80\x82" }, // "る", "。"
230 + { '>' , "\xe3\x80\x82", "\xe3\x80\x82" }, // "。", "。"
231 + { '/' , "\xe3\x82\x81", "\xe3\x83\xbb" }, // "め", "・"
232 + { '?' , "\xe3\x83\xbb", "\xe3\x83\xbb" }, // "・", "・"
233 + { '_' , "\xe3\x82\x8d", "\xe3\x82\x8d" }, // "ろ", "ろ"
234 + // uim distinguishes backslash key and yen key
235 + { '\\', "\xe3\x82\x8d", "\xe3\x82\x8d" }, // "ろ", "ろ"
236 + { UKey_Yen, "\xe3\x83\xbc", "\xe3\x83\xbc" }, // "ー", "ー"
237 +}, kana_map_us[] = {
238 + { '`' , "\xe3\x82\x8d", "\xe3\x82\x8d" }, // "ろ", "ろ"
239 + { '~' , "\xe3\x82\x8d", "\xe3\x82\x8d" }, // "ろ", "ろ"
240 + { '1' , "\xe3\x81\xac", "\xe3\x81\xac" }, // "ぬ", "ぬ"
241 + { '!' , "\xe3\x81\xac", "\xe3\x81\xac" }, // "ぬ", "ぬ"
242 + { '2' , "\xe3\x81\xb5", "\xe3\x81\xb5" }, // "ふ", "ふ"
243 + { '@' , "\xe3\x81\xb5", "\xe3\x81\xb5" }, // "ふ", "ふ"
244 + { '3' , "\xe3\x81\x82", "\xe3\x81\x81" }, // "あ", "ぁ"
245 + { '#' , "\xe3\x81\x81", "\xe3\x81\x81" }, // "ぁ", "ぁ"
246 + { '4' , "\xe3\x81\x86", "\xe3\x81\x85" }, // "う", "ぅ"
247 + { '$' , "\xe3\x81\x85", "\xe3\x81\x85" }, // "ぅ", "ぅ"
248 + { '5' , "\xe3\x81\x88", "\xe3\x81\x87" }, // "え", "ぇ"
249 + { '%' , "\xe3\x81\x87", "\xe3\x81\x87" }, // "ぇ", "ぇ"
250 + { '6' , "\xe3\x81\x8a", "\xe3\x81\x89" }, // "お", "ぉ"
251 + { '^' , "\xe3\x81\x89", "\xe3\x81\x89" }, // "ぉ", "ぉ"
252 + { '7' , "\xe3\x82\x84", "\xe3\x82\x83" }, // "や", "ゃ"
253 + { '&' , "\xe3\x82\x83", "\xe3\x82\x83" }, // "ゃ", "ゃ"
254 + { '8' , "\xe3\x82\x86", "\xe3\x82\x85" }, // "ゆ", "ゅ"
255 + { '*' , "\xe3\x82\x85", "\xe3\x82\x85" }, // "ゅ", "ゅ"
256 + { '9' , "\xe3\x82\x88", "\xe3\x82\x87" }, // "よ", "ょ"
257 + { '(' , "\xe3\x82\x87", "\xe3\x82\x87" }, // "ょ", "ょ"
258 + { '0' , "\xe3\x82\x8f", "\xe3\x82\x92" }, // "わ", "を"
259 + { ')' , "\xe3\x82\x92", "\xe3\x82\x92" }, // "を", "を"
260 + { '-' , "\xe3\x81\xbb", "\xe3\x83\xbc" }, // "ほ", "ー"
261 + { '_' , "\xe3\x83\xbc", "\xe3\x83\xbc" }, // "ー", "ー"
262 + { '=' , "\xe3\x81\xb8", "\xe3\x81\xb8" }, // "へ", "へ"
263 + { '+' , "\xe3\x81\xb8", "\xe3\x81\xb8" }, // "へ", "へ"
264 + { 'q' , "\xe3\x81\x9f", "\xe3\x81\x9f" }, // "た", "た"
265 + { 'Q' , "\xe3\x81\x9f", "\xe3\x81\x9f" }, // "た", "た"
266 + { 'w' , "\xe3\x81\xa6", "\xe3\x81\xa6" }, // "て", "て"
267 + { 'W' , "\xe3\x81\xa6", "\xe3\x81\xa6" }, // "て", "て"
268 + { 'e' , "\xe3\x81\x84", "\xe3\x81\x83" }, // "い", "ぃ"
269 + { 'E' , "\xe3\x81\x83", "\xe3\x81\x83" }, // "ぃ", "ぃ"
270 + { 'r' , "\xe3\x81\x99", "\xe3\x81\x99" }, // "す", "す"
271 + { 'R' , "\xe3\x81\x99", "\xe3\x81\x99" }, // "す", "す"
272 + { 't' , "\xe3\x81\x8b", "\xe3\x81\x8b" }, // "か", "か"
273 + { 'T' , "\xe3\x81\x8b", "\xe3\x81\x8b" }, // "か", "か"
274 + { 'y' , "\xe3\x82\x93", "\xe3\x82\x93" }, // "ん", "ん"
275 + { 'Y' , "\xe3\x82\x93", "\xe3\x82\x93" }, // "ん", "ん"
276 + { 'u' , "\xe3\x81\xaa", "\xe3\x81\xaa" }, // "な", "な"
277 + { 'U' , "\xe3\x81\xaa", "\xe3\x81\xaa" }, // "な", "な"
278 + { 'i' , "\xe3\x81\xab", "\xe3\x81\xab" }, // "に", "に"
279 + { 'I' , "\xe3\x81\xab", "\xe3\x81\xab" }, // "に", "に"
280 + { 'o' , "\xe3\x82\x89", "\xe3\x82\x89" }, // "ら", "ら"
281 + { 'O' , "\xe3\x82\x89", "\xe3\x82\x89" }, // "ら", "ら"
282 + { 'p' , "\xe3\x81\x9b", "\xe3\x81\x9b" }, // "せ", "せ"
283 + { 'P' , "\xe3\x81\x9b", "\xe3\x81\x9b" }, // "せ", "せ"
284 + { '[' , "\xe3\x82\x9b", "\xe3\x82\x9b" }, // "゛", "゛"
285 + { '{' , "\xe3\x82\x9b", "\xe3\x82\x9b" }, // "゛", "゛"
286 + { ']' , "\xe3\x82\x9c", "\xe3\x80\x8c" }, // "゜", "「"
287 + { '}' , "\xe3\x80\x8c", "\xe3\x80\x8c" }, // "「", "「"
288 + { '\\', "\xe3\x82\x80", "\xe3\x80\x8d" }, // "む", "」"
289 + { '|' , "\xe3\x80\x8d", "\xe3\x80\x8d" }, // "」", "」"
290 + { 'a' , "\xe3\x81\xa1", "\xe3\x81\xa1" }, // "ち", "ち"
291 + { 'A' , "\xe3\x81\xa1", "\xe3\x81\xa1" }, // "ち", "ち"
292 + { 's' , "\xe3\x81\xa8", "\xe3\x81\xa8" }, // "と", "と"
293 + { 'S' , "\xe3\x81\xa8", "\xe3\x81\xa8" }, // "と", "と"
294 + { 'd' , "\xe3\x81\x97", "\xe3\x81\x97" }, // "し", "し"
295 + { 'D' , "\xe3\x81\x97", "\xe3\x81\x97" }, // "し", "し"
296 + { 'f' , "\xe3\x81\xaf", "\xe3\x81\xaf" }, // "は", "は"
297 + { 'F' , "\xe3\x81\xaf", "\xe3\x81\xaf" }, // "は", "は"
298 + { 'g' , "\xe3\x81\x8d", "\xe3\x81\x8d" }, // "き", "き"
299 + { 'G' , "\xe3\x81\x8d", "\xe3\x81\x8d" }, // "き", "き"
300 + { 'h' , "\xe3\x81\x8f", "\xe3\x81\x8f" }, // "く", "く"
301 + { 'H' , "\xe3\x81\x8f", "\xe3\x81\x8f" }, // "く", "く"
302 + { 'j' , "\xe3\x81\xbe", "\xe3\x81\xbe" }, // "ま", "ま"
303 + { 'J' , "\xe3\x81\xbe", "\xe3\x81\xbe" }, // "ま", "ま"
304 + { 'k' , "\xe3\x81\xae", "\xe3\x81\xae" }, // "の", "の"
305 + { 'K' , "\xe3\x81\xae", "\xe3\x81\xae" }, // "の", "の"
306 + { 'l' , "\xe3\x82\x8a", "\xe3\x82\x8a" }, // "り", "り"
307 + { 'L' , "\xe3\x82\x8a", "\xe3\x82\x8a" }, // "り", "り"
308 + { ';' , "\xe3\x82\x8c", "\xe3\x82\x8c" }, // "れ", "れ"
309 + { ':' , "\xe3\x82\x8c", "\xe3\x82\x8c" }, // "れ", "れ"
310 + { '\'', "\xe3\x81\x91", "\xe3\x81\x91" }, // "け", "け"
311 + { '\"', "\xe3\x81\x91", "\xe3\x81\x91" }, // "け", "け"
312 + { 'z' , "\xe3\x81\xa4", "\xe3\x81\xa3" }, // "つ", "っ"
313 + { 'Z' , "\xe3\x81\xa3", "\xe3\x81\xa3" }, // "っ", "っ"
314 + { 'x' , "\xe3\x81\x95", "\xe3\x81\x95" }, // "さ", "さ"
315 + { 'X' , "\xe3\x81\x95", "\xe3\x81\x95" }, // "さ", "さ"
316 + { 'c' , "\xe3\x81\x9d", "\xe3\x81\x9d" }, // "そ", "そ"
317 + { 'C' , "\xe3\x81\x9d", "\xe3\x81\x9d" }, // "そ", "そ"
318 + { 'v' , "\xe3\x81\xb2", "\xe3\x81\xb2" }, // "ひ", "ひ"
319 + { 'V' , "\xe3\x81\xb2", "\xe3\x81\xb2" }, // "ひ", "ひ"
320 + { 'b' , "\xe3\x81\x93", "\xe3\x81\x93" }, // "こ", "こ"
321 + { 'B' , "\xe3\x81\x93", "\xe3\x81\x93" }, // "こ", "こ"
322 + { 'n' , "\xe3\x81\xbf", "\xe3\x81\xbf" }, // "み", "み"
323 + { 'N' , "\xe3\x81\xbf", "\xe3\x81\xbf" }, // "み", "み"
324 + { 'm' , "\xe3\x82\x82", "\xe3\x82\x82" }, // "も", "も"
325 + { 'M' , "\xe3\x82\x82", "\xe3\x82\x82" }, // "も", "も"
326 + { ',' , "\xe3\x81\xad", "\xe3\x80\x81" }, // "ね", "、"
327 + { '<' , "\xe3\x80\x81", "\xe3\x80\x81" }, // "、", "、"
328 + { '.' , "\xe3\x82\x8b", "\xe3\x80\x82" }, // "る", "。"
329 + { '>' , "\xe3\x80\x82", "\xe3\x80\x82" }, // "。", "。"
330 + { '/' , "\xe3\x82\x81", "\xe3\x83\xbb" }, // "め", "・"
331 + { '?' , "\xe3\x83\xbb", "\xe3\x83\xbb" }, // "・", "・"
332 + { UKey_Yen, "\xe3\x83\xbc", "\xe3\x83\xbc" }, // "ー", "ー"
333 +};
334 +
335 +} // namespace
336 +
337 +namespace mozc {
338 +namespace uim {
339 +
340 +KeyTranslator::KeyTranslator() {
341 + Init();
342 +}
343 +
344 +KeyTranslator::~KeyTranslator() {
345 +}
346 +
347 +bool KeyTranslator::Translate(unsigned int keyval,
348 + unsigned int keycode,
349 + unsigned int modifiers,
350 + config::Config::PreeditMethod method,
351 + bool layout_is_jp,
352 + commands::KeyEvent *out_event) const {
353 + DCHECK(out_event) << "out_event is NULL";
354 + out_event->Clear();
355 +
356 + string kana_key_string;
357 + if ((method == config::Config::KANA) && IsKanaAvailable(
358 + keyval, keycode, modifiers, layout_is_jp, &kana_key_string)) {
359 + out_event->set_key_code(keyval);
360 + out_event->set_key_string(kana_key_string);
361 + } else if (IsAscii(keyval, keycode, modifiers)) {
362 + out_event->set_key_code(keyval);
363 + } else if (IsModifierKey(keyval, keycode, modifiers)) {
364 + ModifierKeyMap::const_iterator i = modifier_key_map_.find(keyval);
365 + DCHECK(i != modifier_key_map_.end());
366 + out_event->add_modifier_keys((*i).second);
367 + } else if (IsSpecialKey(keyval, keycode, modifiers)) {
368 + SpecialKeyMap::const_iterator i = special_key_map_.find(keyval);
369 + DCHECK(i != special_key_map_.end());
370 + out_event->set_special_key((*i).second);
371 + } else if ((method == config::Config::ROMAN) && keyval == UKey_Yen) {
372 + /* regards yen key as backslash */
373 + out_event->set_key_code('\\');
374 + } else {
375 + VLOG(1) << "Unknown keyval: " << keyval;
376 + return false;
377 + }
378 +
379 + for (ModifierKeyMap::const_iterator i = modifier_mask_map_.begin();
380 + i != modifier_mask_map_.end();
381 + ++i) {
382 + // Do not set a SHIFT modifier when |keyval| is a printable key by following
383 + // the Mozc's rule.
384 + if (((*i).second == commands::KeyEvent::SHIFT) &&
385 + IsAscii(keyval, keycode, modifiers)) {
386 + continue;
387 + }
388 +
389 + if ((*i).first & modifiers) {
390 + out_event->add_modifier_keys((*i).second);
391 + }
392 + }
393 +
394 + return true;
395 +}
396 +
397 +void KeyTranslator::Init() {
398 + for (int i = 0; i < arraysize(special_key_map); ++i) {
399 + CHECK(special_key_map_.insert(make_pair(special_key_map[i].from,
400 + special_key_map[i].to)).second);
401 + }
402 + for (int i = 0; i < arraysize(modifier_key_map); ++i) {
403 + CHECK(modifier_key_map_.insert(make_pair(modifier_key_map[i].from,
404 + modifier_key_map[i].to)).second);
405 + }
406 + for (int i = 0; i < arraysize(modifier_mask_map); ++i) {
407 + CHECK(modifier_mask_map_.insert(make_pair(modifier_mask_map[i].from,
408 + modifier_mask_map[i].to)).second);
409 + }
410 + for (int i = 0; i < arraysize(kana_map_jp); ++i) {
411 + CHECK(kana_map_jp_.insert(
412 + make_pair(kana_map_jp[i].code, make_pair(
413 + kana_map_jp[i].no_shift, kana_map_jp[i].shift))).second);
414 + }
415 + for (int i = 0; i < arraysize(kana_map_us); ++i) {
416 + CHECK(kana_map_us_.insert(
417 + make_pair(kana_map_us[i].code, make_pair(
418 + kana_map_us[i].no_shift, kana_map_us[i].shift))).second);
419 + }
420 +}
421 +
422 +bool KeyTranslator::IsModifierKey(unsigned int keyval,
423 + unsigned int keycode,
424 + unsigned int modifiers) const {
425 + return modifier_key_map_.find(keyval) != modifier_key_map_.end();
426 +}
427 +
428 +bool KeyTranslator::IsSpecialKey(unsigned int keyval,
429 + unsigned int keycode,
430 + unsigned int modifiers) const {
431 + return special_key_map_.find(keyval) != special_key_map_.end();
432 +}
433 +
434 +bool KeyTranslator::IsKanaAvailable(unsigned int keyval,
435 + unsigned int keycode,
436 + unsigned int modifiers,
437 + bool layout_is_jp,
438 + string *out) const {
439 + if ((modifiers & UMod_Control) || (modifiers & UMod_Alt)) {
440 + return false;
441 + }
442 + const KanaMap &kana_map = layout_is_jp ? kana_map_jp_ : kana_map_us_;
443 + KanaMap::const_iterator iter = kana_map.find(keyval);
444 + if (iter == kana_map.end()) {
445 + return false;
446 + }
447 +
448 + if (out)
449 + *out = (modifiers & UMod_Shift) ?
450 + iter->second.second : iter->second.first;
451 +
452 + return true;
453 +}
454 +
455 +bool KeyTranslator::IsAscii(unsigned int keyval,
456 + unsigned int keycode,
457 + unsigned int modifiers) {
458 + return (keyval > 0x20 &&
459 + // Note: Space key (0x20) is a special key in Mozc.
460 + keyval <= 0x7e); // ~
461 +}
462 +
463 +} // namespace uim
464 +} // namespace mozc
465 diff --git a/unix/uim/key_translator.h b/unix/uim/key_translator.h
466 new file mode 100644
467 index 0000000..be58c9b
468 --- /dev/null
469 +++ b/unix/uim/key_translator.h
470 @@ -0,0 +1,111 @@
471 +// Copyright 2010, Google Inc.
472 +// Copyright (c) 2010 uim Project http://code.google.com/p/uim/
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 authors 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..80d54fa
585 --- /dev/null
586 +++ b/unix/uim/mozc.cc
587 @@ -0,0 +1,992 @@
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_REQUIRE(1, 6, 0)
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 + commands::Output *output;
677 + commands::CompositionMode currentMode;
678 + bool has_preedit_before;
679 + int cand_nr_before;
680 + uint64 last_sync_time;
681 +#if USE_CASCADING_CANDIDATES
682 + vector<int32> *unique_candidate_ids;
683 +#endif
684 + config::Config::PreeditMethod preedit_method;
685 +} *context_slot;
686 +
687 +static KeyTranslator *keyTranslator;
688 +
689 +static int
690 +unused_context_id(void)
691 +{
692 + int i;
693 +
694 + for (i = 0; i < nr_contexts; i++) {
695 + if (!context_slot[i].session)
696 + return i;
697 + }
698 +
699 + nr_contexts++;
700 + context_slot = (context_slot_ *)uim_realloc(context_slot, sizeof(struct context_slot_) * (nr_contexts));
701 +
702 + return i;
703 +}
704 +
705 +static void
706 +SyncData(int id, bool force)
707 +{
708 + if (context_slot[id].session == NULL)
709 + return;
710 +
711 + const uint64 current_time = GetTime();
712 + if (force ||
713 + (current_time >= context_slot[id].last_sync_time &&
714 + current_time - context_slot[id].last_sync_time >= kSyncDataInterval)) {
715 + context_slot[id].session->SyncData();
716 + context_slot[id].last_sync_time = current_time;
717 + }
718 +}
719 +
720 +static void
721 +update_result(uim_lisp mc_, int id)
722 +{
723 + commands::Output *output = context_slot[id].output;
724 +
725 + if (!output->has_result())
726 + return;
727 +
728 + const char *str = output->result().value().c_str();
729 + uim_scm_callf("im-commit", "os", mc_, str);
730 +}
731 +
732 +static uim_lisp
733 +insert_cursor(uim_lisp segs, const commands::Preedit::Segment &segment, int attr, int pos)
734 +{
735 + size_t len = segment.value_length();
736 +
737 + string former = Util::SubString(segment.value(), 0, pos);
738 + string latter = Util::SubString(segment.value(), pos, len);
739 +
740 + uim_lisp seg_f, seg_c, seg_l;
741 + if (pos == 0) {
742 + seg_f = uim_scm_null(); /* not used */
743 + seg_c = CONS(MAKE_INT(UPreeditAttr_Cursor), MAKE_STR(""));
744 + seg_l = CONS(MAKE_INT(attr), MAKE_STR(latter.c_str()));
745 +
746 + segs = CONS(seg_c, segs);
747 + segs = CONS(seg_l, segs);
748 + } else {
749 + seg_f = CONS(MAKE_INT(attr), MAKE_STR(former.c_str()));
750 + seg_c = CONS(MAKE_INT(UPreeditAttr_Cursor), MAKE_STR(""));
751 + seg_l = CONS(MAKE_INT(attr), MAKE_STR(latter.c_str()));
752 +
753 + segs = CONS(seg_f, segs);
754 + segs = CONS(seg_c, segs);
755 + segs = CONS(seg_l, segs);
756 + }
757 +
758 + return segs;
759 +}
760 +
761 +static uim_lisp
762 +compose_preedit(const commands::Output *output)
763 +{
764 + const commands::Preedit &preedit = output->preedit();
765 + uim_lisp segs = uim_scm_null();
766 + uim_lisp separator = uim_scm_callf("mozc-separator", "");
767 + int cursorPos;
768 + int count = 0;
769 + int seg_count = preedit.segment_size();
770 +
771 + cursorPos = output->preedit().cursor();
772 +
773 + for (int i = 0; i < seg_count; ++i) {
774 + const commands::Preedit::Segment segment = preedit.segment(i);
775 + const char *str = segment.value().c_str();
776 + int attr;
777 + int prev_count = count;
778 + uim_lisp seg;
779 + count += segment.value_length();
780 +
781 + switch (segment.annotation()) {
782 + case commands::Preedit::Segment::NONE:
783 + attr = UPreeditAttr_None;
784 + break;
785 + case commands::Preedit::Segment::UNDERLINE:
786 + attr = UPreeditAttr_UnderLine;
787 + break;
788 + case commands::Preedit::Segment::HIGHLIGHT:
789 + attr = UPreeditAttr_Reverse | UPreeditAttr_Cursor;
790 + break;
791 + default:
792 + attr = UPreeditAttr_None;
793 + break;
794 + }
795 +
796 + if (((prev_count < cursorPos) && (count > cursorPos)) || cursorPos == 0) {
797 + uim_lisp new_segs;
798 + if ((new_segs = insert_cursor(segs, segment, attr, cursorPos - prev_count)) != uim_scm_null()) {
799 + segs = new_segs;
800 + continue;
801 + }
802 + }
803 +
804 + seg = CONS(MAKE_INT(attr), MAKE_STR(str));
805 +
806 + if (TRUEP(separator) && i > 0)
807 + segs = CONS(separator, segs);
808 + segs = CONS(seg, segs);
809 +
810 + if (count == cursorPos && !output->preedit().has_highlighted_position()) {
811 + seg = CONS(MAKE_INT(UPreeditAttr_Cursor), MAKE_STR(""));
812 + segs = CONS(seg, segs);
813 + }
814 + }
815 +
816 + return uim_scm_callf("reverse", "o", segs);
817 +}
818 +
819 +static void
820 +update_preedit(uim_lisp mc_, int id)
821 +{
822 + uim_lisp preedit;
823 + commands::Output *output = context_slot[id].output;
824 +
825 + if (!output->has_preedit()) {
826 + if (context_slot[id].has_preedit_before) {
827 + uim_scm_callf("context-update-preedit", "oo", mc_, uim_scm_null());
828 + }
829 + context_slot[id].has_preedit_before = false;
830 +
831 + return;
832 + } else {
833 + preedit = compose_preedit(output);
834 + context_slot[id].has_preedit_before = true;
835 + }
836 + uim_scm_callf("context-update-preedit", "oo", mc_, preedit);
837 +}
838 +
839 +static void
840 +update_candidates(uim_lisp mc_, int id)
841 +{
842 + commands::Output *output = context_slot[id].output;
843 +
844 + if (!output->has_candidates()) {
845 + uim_scm_callf("im-deactivate-candidate-selector", "o", mc_);
846 + context_slot[id].cand_nr_before = 0;
847 +
848 + return;
849 + }
850 +
851 + const commands::Candidates &candidates = output->candidates();
852 + bool first_time = false;
853 +
854 + if ((context_slot[id].cand_nr_before != candidates.size()) || !candidates.focused_index())
855 + first_time = true;
856 +
857 + if (first_time)
858 + uim_scm_callf("im-activate-candidate-selector", "oii", mc_, candidates.size(), 9);
859 +
860 + if (candidates.has_focused_index()) {
861 + int index = candidates.focused_index();
862 + uim_scm_callf("im-select-candidate", "oi", mc_, index);
863 + }
864 + context_slot[id].cand_nr_before = candidates.size();
865 +
866 +#if USE_CASCADING_CANDIDATES
867 + if (first_time || (candidates.has_focused_index() && candidates.focused_index() % 9 == 0)) {
868 + context_slot[id].unique_candidate_ids->clear();
869 + for (int i = 0; i < candidates.candidate_size(); ++i) {
870 + if (candidates.candidate(i).has_id()) {
871 + const int32 cand_id = candidates.candidate(i).id();
872 + context_slot[id].unique_candidate_ids->push_back(cand_id);
873 + } else {
874 + // The parent node of the cascading window does not have an id since the
875 + // node does not contain a candidate word.
876 + context_slot[id].unique_candidate_ids->push_back(kBadCandidateId);
877 + }
878 + }
879 + }
880 +#endif
881 +}
882 +
883 +static void
884 +update_composition_mode(uim_lisp mc_, int id)
885 +{
886 + commands::Output *output = context_slot[id].output;
887 +
888 + if (!output->has_mode())
889 + return;
890 +
891 + const commands::CompositionMode newMode = output->mode();
892 + if (context_slot[id].currentMode == newMode)
893 + return;
894 +
895 + context_slot[id].currentMode = newMode;
896 +}
897 +
898 +static void
899 +update_all(uim_lisp mc_, int id)
900 +{
901 + update_result(mc_, id);
902 + update_preedit(mc_, id);
903 + update_candidates(mc_, id);
904 + update_composition_mode(mc_, id);
905 +}
906 +
907 +static uim_lisp
908 +create_context(uim_lisp mc_)
909 +{
910 + int id;
911 +
912 + client::SessionInterface *session = new client::Session;
913 + commands::Output *output = new commands::Output;
914 + if (!keyTranslator)
915 + keyTranslator = new KeyTranslator;
916 +
917 + id = unused_context_id();
918 + context_slot[id].session = session;
919 + context_slot[id].output = output;
920 + context_slot[id].currentMode = commands::HIRAGANA;
921 + context_slot[id].has_preedit_before = false;
922 + context_slot[id].cand_nr_before = 0;
923 +#if USE_CASCADING_CANDIDATES
924 + context_slot[id].unique_candidate_ids = new vector<int32>;
925 +#endif
926 +
927 + // Launch mozc_server
928 + // or should I call this with mozc-on-key?
929 + session->EnsureConnection();
930 +#if !USE_CASCADING_CANDIDATES
931 + session->EnableCascadingWindow(false);
932 +#endif
933 +
934 + return MAKE_INT(id);
935 +}
936 +
937 +static uim_lisp
938 +release_context(uim_lisp id_)
939 +{
940 + int id = C_INT(id_);
941 +
942 + if (id < nr_contexts) {
943 + SyncData(id, true);
944 + delete context_slot[id].session;
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].output = NULL;
951 + }
952 +
953 + return uim_scm_f();
954 +}
955 +
956 +static uim_lisp
957 +reset_context(uim_lisp id_)
958 +{
959 + return uim_scm_t();
960 +}
961 +
962 +static uim_lisp
963 +press_key(uim_lisp mc_, uim_lisp id_, uim_lisp key_, uim_lisp state_)
964 +{
965 + client::SessionInterface *session;
966 + commands::KeyEvent key;
967 + int id;
968 + int keyval, keycode, modifiers;
969 + config::Config::PreeditMethod preedit_method;
970 + char *keyboard;
971 + bool layout_is_jp;
972 +
973 + id = C_INT(id_);
974 + session = context_slot[id].session;
975 + preedit_method = context_slot[id].preedit_method;
976 + keyboard = uim_scm_symbol_value_str("mozc-keyboard-type-for-kana-input-method");
977 + layout_is_jp = keyboard && !strcmp(keyboard, "jp-keyboard") ? true : false;
978 + free(keyboard);
979 +
980 + keyval = C_INT(key_);
981 + modifiers = C_INT(state_);
982 + keycode = 0; /* XXX */
983 +
984 + if (!(*keyTranslator).Translate(keyval, keycode, modifiers, preedit_method, layout_is_jp, &key))
985 + return uim_scm_f();
986 +
987 + if (!(*session).SendKey(key, context_slot[id].output))
988 + return uim_scm_f();
989 +
990 + update_all(mc_, id);
991 +
992 + const bool consumed = context_slot[id].output->consumed();
993 +#if 0
994 + fprintf(stderr, "debugstring %s\n", output.DebugString().c_str());
995 + fprintf(stderr, "consumed %d\n", consumed ? 1 : 0);
996 +#endif
997 +
998 + return consumed ? uim_scm_t() : uim_scm_f();
999 +}
1000 +
1001 +static uim_lisp
1002 +release_key(uim_lisp id_, uim_lisp key_, uim_lisp state_)
1003 +{
1004 + return uim_scm_f();
1005 +}
1006 +
1007 +static uim_lisp
1008 +get_nr_candidates(uim_lisp id_)
1009 +{
1010 + int id = C_INT(id_);
1011 + commands::Output *output = context_slot[id].output;
1012 +
1013 + return MAKE_INT(output->candidates().size());
1014 +}
1015 +
1016 +static uim_lisp
1017 +get_nth_candidate(uim_lisp id_, uim_lisp nth_)
1018 +{
1019 + int id = C_INT(id_);
1020 + commands::Output *output = context_slot[id].output;
1021 + const commands::Candidates &candidates = output->candidates();
1022 + const char *cand;
1023 +
1024 + int nth;
1025 + int idx;
1026 + int nr;
1027 +
1028 + nth = C_INT(nth_);
1029 + nr = candidates.size();
1030 +