Skip to content
This repository has been archived by the owner on Feb 11, 2021. It is now read-only.

Latest commit

 

History

History
1584 lines (1391 loc) · 52.3 KB

SDL_windowskeyboard.c

File metadata and controls

1584 lines (1391 loc) · 52.3 KB
 
Apr 26, 2001
Apr 26, 2001
1
2
/*
SDL - Simple DirectMedia Layer
Jan 24, 2010
Jan 24, 2010
3
Copyright (C) 1997-2010 Sam Lantinga
Apr 26, 2001
Apr 26, 2001
4
5
This library is free software; you can redistribute it and/or
Feb 1, 2006
Feb 1, 2006
6
modify it under the terms of the GNU Lesser General Public
Apr 26, 2001
Apr 26, 2001
7
License as published by the Free Software Foundation; either
Feb 1, 2006
Feb 1, 2006
8
version 2.1 of the License, or (at your option) any later version.
Apr 26, 2001
Apr 26, 2001
9
10
11
12
This library is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
Feb 1, 2006
Feb 1, 2006
13
Lesser General Public License for more details.
Apr 26, 2001
Apr 26, 2001
14
Feb 1, 2006
Feb 1, 2006
15
16
17
You should have received a copy of the GNU Lesser General Public
License along with this library; if not, write to the Free Software
Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
Apr 26, 2001
Apr 26, 2001
18
19
Sam Lantinga
Dec 14, 2001
Dec 14, 2001
20
slouken@libsdl.org
Apr 26, 2001
Apr 26, 2001
21
*/
Feb 21, 2006
Feb 21, 2006
22
#include "SDL_config.h"
Apr 26, 2001
Apr 26, 2001
23
Jan 24, 2011
Jan 24, 2011
24
25
26
27
#ifdef _WIN32_WCE
#define SDL_DISABLE_WINDOWS_IME
#endif
Jan 21, 2011
Jan 21, 2011
28
#include "SDL_windowsvideo.h"
Apr 26, 2001
Apr 26, 2001
29
Jul 10, 2006
Jul 10, 2006
30
#include "../../events/SDL_keyboard_c.h"
Jan 21, 2011
Jan 21, 2011
31
#include "../../events/scancodes_windows.h"
Apr 26, 2001
Apr 26, 2001
32
Jul 12, 2010
Jul 12, 2010
33
#include <imm.h>
Aug 3, 2010
Aug 3, 2010
34
35
#include <oleauto.h>
Jan 24, 2011
Jan 24, 2011
36
#ifndef SDL_DISABLE_WINDOWS_IME
Aug 3, 2010
Aug 3, 2010
37
38
39
40
static void IME_Init(SDL_VideoData *videodata, HWND hwnd);
static void IME_Enable(SDL_VideoData *videodata, HWND hwnd);
static void IME_Disable(SDL_VideoData *videodata, HWND hwnd);
static void IME_Quit(SDL_VideoData *videodata);
Jan 24, 2011
Jan 24, 2011
41
#endif /* !SDL_DISABLE_WINDOWS_IME */
Jul 12, 2010
Jul 12, 2010
42
Feb 9, 2008
Feb 9, 2008
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
#ifndef MAPVK_VK_TO_VSC
#define MAPVK_VK_TO_VSC 0
#endif
#ifndef MAPVK_VSC_TO_VK
#define MAPVK_VSC_TO_VK 1
#endif
#ifndef MAPVK_VK_TO_CHAR
#define MAPVK_VK_TO_CHAR 2
#endif
/* Alphabetic scancodes for PC keyboards */
BYTE alpha_scancodes[26] = {
30, 48, 46, 32, 18, 33, 34, 35, 23, 36, 37, 38, 50, 49, 24,
25, 16, 19, 31, 20, 22, 47, 17, 45, 21, 44
};
Aug 27, 2008
Aug 27, 2008
58
Feb 11, 2008
Feb 11, 2008
59
60
61
BYTE keypad_scancodes[10] = {
82, 79, 80, 81, 75, 76, 77, 71, 72, 73
};
Feb 9, 2008
Feb 9, 2008
62
Jul 10, 2006
Jul 10, 2006
63
64
65
66
void
WIN_InitKeyboard(_THIS)
{
SDL_VideoData *data = (SDL_VideoData *) _this->driverdata;
Feb 9, 2008
Feb 9, 2008
67
68
69
int i;
/* Make sure the alpha scancodes are correct. T isn't usually remapped */
Mar 7, 2008
Mar 7, 2008
70
if (MapVirtualKey('T', MAPVK_VK_TO_VSC) != alpha_scancodes['T' - 'A']) {
Aug 26, 2008
Aug 26, 2008
71
#if 0
Aug 26, 2008
Aug 26, 2008
72
73
printf
("Fixing alpha scancode map, assuming US QWERTY layout!\nPlease send the following 26 lines of output to the SDL mailing list <sdl@libsdl.org>, including a description of your keyboard hardware.\n");
Aug 26, 2008
Aug 26, 2008
74
#endif
Feb 9, 2008
Feb 9, 2008
75
for (i = 0; i < SDL_arraysize(alpha_scancodes); ++i) {
Mar 7, 2008
Mar 7, 2008
76
alpha_scancodes[i] = MapVirtualKey('A' + i, MAPVK_VK_TO_VSC);
Aug 26, 2008
Aug 26, 2008
77
#if 0
Mar 7, 2008
Mar 7, 2008
78
printf("%d = %d\n", i, alpha_scancodes[i]);
Aug 26, 2008
Aug 26, 2008
79
#endif
Feb 9, 2008
Feb 9, 2008
80
81
}
}
Feb 11, 2008
Feb 11, 2008
82
if (MapVirtualKey(VK_NUMPAD0, MAPVK_VK_TO_VSC) != keypad_scancodes[0]) {
Aug 26, 2008
Aug 26, 2008
83
#if 0
Aug 26, 2008
Aug 26, 2008
84
85
printf
("Fixing keypad scancode map!\nPlease send the following 10 lines of output to the SDL mailing list <sdl@libsdl.org>, including a description of your keyboard hardware.\n");
Aug 26, 2008
Aug 26, 2008
86
#endif
Feb 11, 2008
Feb 11, 2008
87
for (i = 0; i < SDL_arraysize(keypad_scancodes); ++i) {
Mar 7, 2008
Mar 7, 2008
88
89
keypad_scancodes[i] =
MapVirtualKey(VK_NUMPAD0 + i, MAPVK_VK_TO_VSC);
Aug 26, 2008
Aug 26, 2008
90
#if 0
Mar 7, 2008
Mar 7, 2008
91
printf("%d = %d\n", i, keypad_scancodes[i]);
Aug 26, 2008
Aug 26, 2008
92
#endif
Feb 11, 2008
Feb 11, 2008
93
94
}
}
Apr 26, 2001
Apr 26, 2001
95
Jan 21, 2011
Jan 21, 2011
96
data->key_layout = windows_scancode_table;
Feb 8, 2008
Feb 8, 2008
97
Jul 12, 2010
Jul 12, 2010
98
data->ime_com_initialized = SDL_FALSE;
Aug 3, 2010
Aug 3, 2010
99
data->ime_threadmgr = 0;
Jul 12, 2010
Jul 12, 2010
100
101
102
103
104
105
data->ime_initialized = SDL_FALSE;
data->ime_enabled = SDL_FALSE;
data->ime_available = SDL_FALSE;
data->ime_hwnd_main = 0;
data->ime_hwnd_current = 0;
data->ime_himc = 0;
Aug 3, 2010
Aug 3, 2010
106
107
108
data->ime_composition[0] = 0;
data->ime_readingstring[0] = 0;
data->ime_cursor = 0;
Nov 23, 2010
Nov 23, 2010
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
data->ime_candlist = SDL_FALSE;
SDL_memset(data->ime_candidates, 0, sizeof(data->ime_candidates));
data->ime_candcount = 0;
data->ime_candref = 0;
data->ime_candsel = 0;
data->ime_candpgsize = 0;
data->ime_candlistindexbase = 0;
data->ime_candvertical = SDL_TRUE;
data->ime_candtex = NULL;
data->ime_dirty = SDL_FALSE;
SDL_memset(&data->ime_rect, 0, sizeof(data->ime_rect));
SDL_memset(&data->ime_candlistrect, 0, sizeof(data->ime_candlistrect));
data->ime_winwidth = 0;
data->ime_winheight = 0;
Aug 3, 2010
Aug 3, 2010
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
data->ime_hkl = 0;
data->ime_himm32 = 0;
data->GetReadingString = 0;
data->ShowReadingWindow = 0;
data->ImmLockIMC = 0;
data->ImmUnlockIMC = 0;
data->ImmLockIMCC = 0;
data->ImmUnlockIMCC = 0;
data->ime_uiless = SDL_FALSE;
data->ime_threadmgrex = 0;
data->ime_uielemsinkcookie = TF_INVALID_COOKIE;
data->ime_alpnsinkcookie = TF_INVALID_COOKIE;
data->ime_openmodesinkcookie = TF_INVALID_COOKIE;
data->ime_convmodesinkcookie = TF_INVALID_COOKIE;
data->ime_uielemsink = 0;
data->ime_ippasink = 0;
Jul 12, 2010
Jul 12, 2010
142
May 10, 2010
May 10, 2010
143
WIN_UpdateKeymap();
Feb 8, 2008
Feb 8, 2008
144
145
146
147
148
149
150
SDL_SetScancodeName(SDL_SCANCODE_APPLICATION, "Menu");
SDL_SetScancodeName(SDL_SCANCODE_LGUI, "Left Windows");
SDL_SetScancodeName(SDL_SCANCODE_RGUI, "Right Windows");
}
void
May 10, 2010
May 10, 2010
151
WIN_UpdateKeymap()
Feb 8, 2008
Feb 8, 2008
152
153
{
int i;
Jan 24, 2011
Jan 24, 2011
154
SDL_ScanCode scancode;
Feb 8, 2008
Feb 8, 2008
155
156
157
158
SDLKey keymap[SDL_NUM_SCANCODES];
SDL_GetDefaultKeymap(keymap);
Jan 21, 2011
Jan 21, 2011
159
for (i = 0; i < SDL_arraysize(windows_scancode_table); i++) {
Feb 8, 2008
Feb 8, 2008
160
161
/* Make sure this scancode is a valid character scancode */
Jan 21, 2011
Jan 21, 2011
162
scancode = windows_scancode_table[i];
Jul 21, 2010
Jul 21, 2010
163
if (scancode == SDL_SCANCODE_UNKNOWN || keymap[scancode] >= 127) {
Feb 8, 2008
Feb 8, 2008
164
165
continue;
}
Feb 9, 2008
Feb 9, 2008
166
167
168
/* Alphabetic keys are handled specially, since Windows remaps them */
if (i >= 'A' && i <= 'Z') {
Mar 7, 2008
Mar 7, 2008
169
BYTE vsc = alpha_scancodes[i - 'A'];
Feb 9, 2008
Feb 9, 2008
170
171
172
173
keymap[scancode] = MapVirtualKey(vsc, MAPVK_VSC_TO_VK) + 0x20;
} else {
keymap[scancode] = (MapVirtualKey(i, MAPVK_VK_TO_CHAR) & 0x7FFF);
}
Feb 8, 2008
Feb 8, 2008
174
}
May 10, 2010
May 10, 2010
175
SDL_SetKeymap(0, keymap, SDL_NUM_SCANCODES);
Jul 10, 2006
Jul 10, 2006
176
177
178
179
180
}
void
WIN_QuitKeyboard(_THIS)
{
Jan 24, 2011
Jan 24, 2011
181
#ifndef SDL_DISABLE_WINDOWS_IME
Jul 12, 2010
Jul 12, 2010
182
IME_Quit((SDL_VideoData *)_this->driverdata);
Jan 24, 2011
Jan 24, 2011
183
#endif
Jul 10, 2006
Jul 10, 2006
184
185
}
Jul 6, 2010
Jul 6, 2010
186
void
Jul 12, 2010
Jul 12, 2010
187
WIN_StartTextInput(_THIS)
Jul 6, 2010
Jul 6, 2010
188
{
Jan 24, 2011
Jan 24, 2011
189
#ifndef SDL_DISABLE_WINDOWS_IME
Jul 12, 2010
Jul 12, 2010
190
SDL_Window *window = SDL_GetKeyboardFocus();
Aug 3, 2010
Aug 3, 2010
191
if (window) {
Jul 12, 2010
Jul 12, 2010
192
193
HWND hwnd = ((SDL_WindowData *) window->driverdata)->hwnd;
SDL_VideoData *videodata = (SDL_VideoData *)_this->driverdata;
Nov 23, 2010
Nov 23, 2010
194
SDL_GetWindowSize(window, &videodata->ime_winwidth, &videodata->ime_winheight);
Jul 12, 2010
Jul 12, 2010
195
196
197
IME_Init(videodata, hwnd);
IME_Enable(videodata, hwnd);
}
Jan 24, 2011
Jan 24, 2011
198
#endif /* !SDL_DISABLE_WINDOWS_IME */
Jul 6, 2010
Jul 6, 2010
199
200
201
}
void
Jul 12, 2010
Jul 12, 2010
202
WIN_StopTextInput(_THIS)
Jul 6, 2010
Jul 6, 2010
203
{
Jan 24, 2011
Jan 24, 2011
204
#ifndef SDL_DISABLE_WINDOWS_IME
Jul 12, 2010
Jul 12, 2010
205
SDL_Window *window = SDL_GetKeyboardFocus();
Aug 3, 2010
Aug 3, 2010
206
if (window) {
Jul 12, 2010
Jul 12, 2010
207
208
209
210
211
HWND hwnd = ((SDL_WindowData *) window->driverdata)->hwnd;
SDL_VideoData *videodata = (SDL_VideoData *)_this->driverdata;
IME_Init(videodata, hwnd);
IME_Disable(videodata, hwnd);
}
Jan 24, 2011
Jan 24, 2011
212
#endif /* !SDL_DISABLE_WINDOWS_IME */
Jul 6, 2010
Jul 6, 2010
213
214
215
216
217
}
void
WIN_SetTextInputRect(_THIS, SDL_Rect *rect)
{
Nov 23, 2010
Nov 23, 2010
218
219
SDL_VideoData *videodata = (SDL_VideoData *)_this->driverdata;
videodata->ime_rect = *rect;
Jul 6, 2010
Jul 6, 2010
220
221
}
Jan 24, 2011
Jan 24, 2011
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
#ifdef SDL_DISABLE_WINDOWS_IME
SDL_bool
IME_HandleMessage(HWND hwnd, UINT msg, WPARAM wParam, LPARAM *lParam, SDL_VideoData *videodata)
{
return SDL_FALSE;
}
void IME_Present(SDL_VideoData *videodata)
{
}
#else
Sep 19, 2010
Sep 19, 2010
237
238
#ifdef __GNUC__
#undef DEFINE_GUID
Sep 19, 2010
Sep 19, 2010
239
#define DEFINE_GUID(n,l,w1,w2,b1,b2,b3,b4,b5,b6,b7,b8) static const GUID n = {l,w1,w2,{b1,b2,b3,b4,b5,b6,b7,b8}}
Sep 19, 2010
Sep 19, 2010
240
241
242
243
244
DEFINE_GUID(IID_ITfInputProcessorProfileActivationSink, 0x71C6E74E,0x0F28,0x11D8,0xA8,0x2A,0x00,0x06,0x5B,0x84,0x43,0x5C);
DEFINE_GUID(IID_ITfUIElementSink, 0xEA1EA136,0x19DF,0x11D7,0xA6,0xD2,0x00,0x06,0x5B,0x84,0x43,0x5C);
DEFINE_GUID(GUID_TFCAT_TIP_KEYBOARD, 0x34745C63,0xB2F0,0x4784,0x8B,0x67,0x5E,0x12,0xC8,0x70,0x1A,0x31);
DEFINE_GUID(IID_ITfSource, 0x4EA48A35,0x60AE,0x446F,0x8F,0xD6,0xE6,0xA8,0xD8,0x24,0x59,0xF7);
DEFINE_GUID(IID_ITfUIElementMgr, 0xEA1EA135,0x19DF,0x11D7,0xA6,0xD2,0x00,0x06,0x5B,0x84,0x43,0x5C);
Nov 23, 2010
Nov 23, 2010
245
DEFINE_GUID(IID_ITfCandidateListUIElement, 0xEA1EA138,0x19DF,0x11D7,0xA6,0xD2,0x00,0x06,0x5B,0x84,0x43,0x5C);
Sep 19, 2010
Sep 19, 2010
246
247
248
249
250
251
DEFINE_GUID(IID_ITfReadingInformationUIElement, 0xEA1EA139,0x19DF,0x11D7,0xA6,0xD2,0x00,0x06,0x5B,0x84,0x43,0x5C);
DEFINE_GUID(IID_ITfThreadMgr, 0xAA80E801,0x2021,0x11D2,0x93,0xE0,0x00,0x60,0xB0,0x67,0xB8,0x6E);
DEFINE_GUID(CLSID_TF_ThreadMgr, 0x529A9E6B,0x6587,0x4F23,0xAB,0x9E,0x9C,0x7D,0x68,0x3E,0x3C,0x50);
DEFINE_GUID(IID_ITfThreadMgrEx, 0x3E90ADE3,0x7594,0x4CB0,0xBB,0x58,0x69,0x62,0x8F,0x5F,0x45,0x8C);
#endif
Aug 3, 2010
Aug 3, 2010
252
253
#define LANG_CHT MAKELANGID(LANG_CHINESE, SUBLANG_CHINESE_TRADITIONAL)
#define LANG_CHS MAKELANGID(LANG_CHINESE, SUBLANG_CHINESE_SIMPLIFIED)
Jul 12, 2010
Jul 12, 2010
254
Aug 3, 2010
Aug 3, 2010
255
256
257
#define MAKEIMEVERSION(major,minor) ((DWORD) (((BYTE)(major) << 24) | ((BYTE)(minor) << 16) ))
#define IMEID_VER(id) ((id) & 0xffff0000)
#define IMEID_LANG(id) ((id) & 0x0000ffff)
Jul 12, 2010
Jul 12, 2010
258
Aug 3, 2010
Aug 3, 2010
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
#define CHT_HKL_DAYI ((HKL)0xE0060404)
#define CHT_HKL_NEW_PHONETIC ((HKL)0xE0080404)
#define CHT_HKL_NEW_CHANG_JIE ((HKL)0xE0090404)
#define CHT_HKL_NEW_QUICK ((HKL)0xE00A0404)
#define CHT_HKL_HK_CANTONESE ((HKL)0xE00B0404)
#define CHT_IMEFILENAME1 "TINTLGNT.IME"
#define CHT_IMEFILENAME2 "CINTLGNT.IME"
#define CHT_IMEFILENAME3 "MSTCIPHA.IME"
#define IMEID_CHT_VER42 (LANG_CHT | MAKEIMEVERSION(4, 2))
#define IMEID_CHT_VER43 (LANG_CHT | MAKEIMEVERSION(4, 3))
#define IMEID_CHT_VER44 (LANG_CHT | MAKEIMEVERSION(4, 4))
#define IMEID_CHT_VER50 (LANG_CHT | MAKEIMEVERSION(5, 0))
#define IMEID_CHT_VER51 (LANG_CHT | MAKEIMEVERSION(5, 1))
#define IMEID_CHT_VER52 (LANG_CHT | MAKEIMEVERSION(5, 2))
#define IMEID_CHT_VER60 (LANG_CHT | MAKEIMEVERSION(6, 0))
#define IMEID_CHT_VER_VISTA (LANG_CHT | MAKEIMEVERSION(7, 0))
Jul 12, 2010
Jul 12, 2010
275
Aug 3, 2010
Aug 3, 2010
276
277
278
279
280
281
#define CHS_HKL ((HKL)0xE00E0804)
#define CHS_IMEFILENAME1 "PINTLGNT.IME"
#define CHS_IMEFILENAME2 "MSSCIPYA.IME"
#define IMEID_CHS_VER41 (LANG_CHS | MAKEIMEVERSION(4, 1))
#define IMEID_CHS_VER42 (LANG_CHS | MAKEIMEVERSION(4, 2))
#define IMEID_CHS_VER53 (LANG_CHS | MAKEIMEVERSION(5, 3))
Jul 12, 2010
Jul 12, 2010
282
Aug 3, 2010
Aug 3, 2010
283
284
285
#define LANG() LOWORD((videodata->ime_hkl))
#define PRIMLANG() ((WORD)PRIMARYLANGID(LANG()))
#define SUBLANG() SUBLANGID(LANG())
Jul 12, 2010
Jul 12, 2010
286
Aug 3, 2010
Aug 3, 2010
287
288
289
290
291
292
static void IME_UpdateInputLocale(SDL_VideoData *videodata);
static void IME_ClearComposition(SDL_VideoData *videodata);
static void IME_SetWindow(SDL_VideoData* videodata, HWND hwnd);
static void IME_SetupAPI(SDL_VideoData *videodata);
static DWORD IME_GetId(SDL_VideoData *videodata, UINT uIndex);
static void IME_SendEditingEvent(SDL_VideoData *videodata);
Nov 23, 2010
Nov 23, 2010
293
294
static void IME_DestroyTextures(SDL_VideoData *videodata);
Aug 3, 2010
Aug 3, 2010
295
296
#define SDL_IsEqualIID(riid1, riid2) SDL_IsEqualGUID(riid1, riid2)
#define SDL_IsEqualGUID(rguid1, rguid2) (!SDL_memcmp(rguid1, rguid2, sizeof(GUID)))
Jul 12, 2010
Jul 12, 2010
297
Aug 3, 2010
Aug 3, 2010
298
299
300
301
302
303
static SDL_bool UILess_SetupSinks(SDL_VideoData *videodata);
static void UILess_ReleaseSinks(SDL_VideoData *videodata);
static void UILess_EnableUIUpdates(SDL_VideoData *videodata);
static void UILess_DisableUIUpdates(SDL_VideoData *videodata);
static void
Jul 12, 2010
Jul 12, 2010
304
305
306
307
308
309
310
311
IME_Init(SDL_VideoData *videodata, HWND hwnd)
{
if (videodata->ime_initialized)
return;
videodata->ime_hwnd_main = hwnd;
if (SUCCEEDED(CoInitializeEx(NULL, COINIT_APARTMENTTHREADED))) {
videodata->ime_com_initialized = SDL_TRUE;
Sep 19, 2010
Sep 19, 2010
312
CoCreateInstance(&CLSID_TF_ThreadMgr, NULL, CLSCTX_INPROC_SERVER, &IID_ITfThreadMgr, (LPVOID *)&videodata->ime_threadmgr);
Jul 12, 2010
Jul 12, 2010
313
314
}
videodata->ime_initialized = SDL_TRUE;
Jan 25, 2011
Jan 25, 2011
315
videodata->ime_himm32 = SDL_LoadObject("imm32.dll");
Aug 3, 2010
Aug 3, 2010
316
317
318
if (!videodata->ime_himm32) {
videodata->ime_available = SDL_FALSE;
return;
Jul 12, 2010
Jul 12, 2010
319
}
Jan 25, 2011
Jan 25, 2011
320
321
322
323
videodata->ImmLockIMC = (LPINPUTCONTEXT2 (WINAPI *)(HIMC))SDL_LoadFunction(videodata->ime_himm32, "ImmLockIMC");
videodata->ImmUnlockIMC = (BOOL (WINAPI *)(HIMC))SDL_LoadFunction(videodata->ime_himm32, "ImmUnlockIMC");
videodata->ImmLockIMCC = (LPVOID (WINAPI *)(HIMCC))SDL_LoadFunction(videodata->ime_himm32, "ImmLockIMCC");
videodata->ImmUnlockIMCC = (BOOL (WINAPI *)(HIMCC))SDL_LoadFunction(videodata->ime_himm32, "ImmUnlockIMCC");
Aug 3, 2010
Aug 3, 2010
324
325
IME_SetWindow(videodata, hwnd);
Jul 12, 2010
Jul 12, 2010
326
327
328
329
330
331
332
333
videodata->ime_himc = ImmGetContext(hwnd);
ImmReleaseContext(hwnd, videodata->ime_himc);
if (!videodata->ime_himc) {
videodata->ime_available = SDL_FALSE;
IME_Disable(videodata, hwnd);
return;
}
videodata->ime_available = SDL_TRUE;
Aug 3, 2010
Aug 3, 2010
334
335
336
337
IME_UpdateInputLocale(videodata);
IME_SetupAPI(videodata);
videodata->ime_uiless = UILess_SetupSinks(videodata);
IME_UpdateInputLocale(videodata);
Jul 12, 2010
Jul 12, 2010
338
339
340
IME_Disable(videodata, hwnd);
}
Aug 3, 2010
Aug 3, 2010
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
static void
IME_Enable(SDL_VideoData *videodata, HWND hwnd)
{
if (!videodata->ime_initialized || !videodata->ime_hwnd_current)
return;
if (!videodata->ime_available) {
IME_Disable(videodata, hwnd);
return;
}
if (videodata->ime_hwnd_current == videodata->ime_hwnd_main)
ImmAssociateContext(videodata->ime_hwnd_current, videodata->ime_himc);
videodata->ime_enabled = SDL_TRUE;
IME_UpdateInputLocale(videodata);
UILess_EnableUIUpdates(videodata);
}
static void
IME_Disable(SDL_VideoData *videodata, HWND hwnd)
{
if (!videodata->ime_initialized || !videodata->ime_hwnd_current)
return;
IME_ClearComposition(videodata);
if (videodata->ime_hwnd_current == videodata->ime_hwnd_main)
Sep 19, 2010
Sep 19, 2010
367
ImmAssociateContext(videodata->ime_hwnd_current, (HIMC)0);
Aug 3, 2010
Aug 3, 2010
368
369
370
371
372
373
videodata->ime_enabled = SDL_FALSE;
UILess_DisableUIUpdates(videodata);
}
static void
Jul 12, 2010
Jul 12, 2010
374
375
376
377
378
IME_Quit(SDL_VideoData *videodata)
{
if (!videodata->ime_initialized)
return;
Aug 3, 2010
Aug 3, 2010
379
UILess_ReleaseSinks(videodata);
Jul 12, 2010
Jul 12, 2010
380
381
382
383
384
if (videodata->ime_hwnd_main)
ImmAssociateContext(videodata->ime_hwnd_main, videodata->ime_himc);
videodata->ime_hwnd_main = 0;
videodata->ime_himc = 0;
Aug 5, 2010
Aug 5, 2010
385
if (videodata->ime_himm32) {
Jan 25, 2011
Jan 25, 2011
386
SDL_UnloadObject(videodata->ime_himm32);
Aug 3, 2010
Aug 3, 2010
387
388
videodata->ime_himm32 = 0;
}
Aug 5, 2010
Aug 5, 2010
389
if (videodata->ime_threadmgr) {
Aug 3, 2010
Aug 3, 2010
390
391
videodata->ime_threadmgr->lpVtbl->Release(videodata->ime_threadmgr);
videodata->ime_threadmgr = 0;
Jul 12, 2010
Jul 12, 2010
392
}
Aug 5, 2010
Aug 5, 2010
393
if (videodata->ime_com_initialized) {
Jul 12, 2010
Jul 12, 2010
394
395
396
CoUninitialize();
videodata->ime_com_initialized = SDL_FALSE;
}
Nov 23, 2010
Nov 23, 2010
397
IME_DestroyTextures(videodata);
Jul 12, 2010
Jul 12, 2010
398
399
400
videodata->ime_initialized = SDL_FALSE;
}
Aug 3, 2010
Aug 3, 2010
401
402
403
404
405
406
407
408
static void
IME_GetReadingString(SDL_VideoData *videodata, HWND hwnd)
{
DWORD id = 0;
HIMC himc = 0;
WCHAR buffer[16];
WCHAR *s = buffer;
DWORD len = 0;
Sep 19, 2010
Sep 19, 2010
409
INT err = 0;
Aug 3, 2010
Aug 3, 2010
410
411
412
413
414
415
416
BOOL vertical = FALSE;
UINT maxuilen = 0;
static OSVERSIONINFOA osversion = {0};
if (videodata->ime_uiless)
return;
videodata->ime_readingstring[0] = 0;
Aug 5, 2010
Aug 5, 2010
417
if (!osversion.dwOSVersionInfoSize) {
Aug 3, 2010
Aug 3, 2010
418
419
420
421
422
423
424
425
426
427
428
osversion.dwOSVersionInfoSize = sizeof(osversion);
GetVersionExA(&osversion);
}
id = IME_GetId(videodata, 0);
if (!id)
return;
himc = ImmGetContext(hwnd);
if (!himc)
return;
Aug 5, 2010
Aug 5, 2010
429
if (videodata->GetReadingString) {
Aug 3, 2010
Aug 3, 2010
430
len = videodata->GetReadingString(himc, 0, 0, &err, &vertical, &maxuilen);
Aug 5, 2010
Aug 5, 2010
431
if (len) {
Aug 3, 2010
Aug 3, 2010
432
433
434
435
436
437
438
if (len > SDL_arraysize(buffer))
len = SDL_arraysize(buffer);
len = videodata->GetReadingString(himc, len, s, &err, &vertical, &maxuilen);
}
SDL_wcslcpy(videodata->ime_readingstring, s, len);
}
Aug 5, 2010
Aug 5, 2010
439
else {
Aug 3, 2010
Aug 3, 2010
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
LPINPUTCONTEXT2 lpimc = videodata->ImmLockIMC(himc);
LPBYTE p = 0;
s = 0;
switch (id)
{
case IMEID_CHT_VER42:
case IMEID_CHT_VER43:
case IMEID_CHT_VER44:
p = *(LPBYTE *)((LPBYTE)videodata->ImmLockIMCC(lpimc->hPrivate) + 24);
if (!p)
break;
len = *(DWORD *)(p + 7*4 + 32*4);
s = (WCHAR *)(p + 56);
break;
case IMEID_CHT_VER51:
case IMEID_CHT_VER52:
case IMEID_CHS_VER53:
p = *(LPBYTE *)((LPBYTE)videodata->ImmLockIMCC(lpimc->hPrivate) + 4);
if (!p)
break;
p = *(LPBYTE *)((LPBYTE)p + 1*4 + 5*4);
if (!p)
break;
len = *(DWORD *)(p + 1*4 + (16*2+2*4) + 5*4 + 16*2);
s = (WCHAR *)(p + 1*4 + (16*2+2*4) + 5*4);
break;
case IMEID_CHS_VER41:
{
int offset = (IME_GetId(videodata, 1) >= 0x00000002) ? 8 : 7;
p = *(LPBYTE *)((LPBYTE)videodata->ImmLockIMCC(lpimc->hPrivate) + offset * 4);
if (!p)
break;
len = *(DWORD *)(p + 7*4 + 16*2*4);
s = (WCHAR *)(p + 6*4 + 16*2*1);
}
break;
case IMEID_CHS_VER42:
if (osversion.dwPlatformId != VER_PLATFORM_WIN32_NT)
break;
p = *(LPBYTE *)((LPBYTE)videodata->ImmLockIMCC(lpimc->hPrivate) + 1*4 + 1*4 + 6*4);
if (!p)
break;
len = *(DWORD *)(p + 1*4 + (16*2+2*4) + 5*4 + 16*2);
s = (WCHAR *)(p + 1*4 + (16*2+2*4) + 5*4);
break;
}
if (s)
SDL_wcslcpy(videodata->ime_readingstring, s, len + 1);
Aug 5, 2010
Aug 5, 2010
494
Aug 3, 2010
Aug 3, 2010
495
496
497
498
499
500
501
502
503
504
videodata->ImmUnlockIMCC(lpimc->hPrivate);
videodata->ImmUnlockIMC(himc);
}
ImmReleaseContext(hwnd, himc);
IME_SendEditingEvent(videodata);
}
static void
IME_InputLangChanged(SDL_VideoData *videodata)
{
Aug 5, 2010
Aug 5, 2010
505
UINT lang = PRIMLANG();
Aug 3, 2010
Aug 3, 2010
506
IME_UpdateInputLocale(videodata);
Nov 23, 2010
Nov 23, 2010
507
508
509
if (!videodata->ime_uiless)
videodata->ime_candlistindexbase = (videodata->ime_hkl == CHT_HKL_DAYI) ? 0 : 1;
Aug 3, 2010
Aug 3, 2010
510
IME_SetupAPI(videodata);
Aug 5, 2010
Aug 5, 2010
511
if (lang != PRIMLANG()) {
Aug 3, 2010
Aug 3, 2010
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
IME_ClearComposition(videodata);
}
}
static DWORD
IME_GetId(SDL_VideoData *videodata, UINT uIndex)
{
static HKL hklprev = 0;
static DWORD dwRet[2] = {0};
DWORD dwVerSize = 0;
DWORD dwVerHandle = 0;
LPVOID lpVerBuffer = 0;
LPVOID lpVerData = 0;
UINT cbVerData = 0;
char szTemp[256];
HKL hkl = 0;
DWORD dwLang = 0;
if (uIndex >= sizeof(dwRet) / sizeof(dwRet[0]))
return 0;
hkl = videodata->ime_hkl;
if (hklprev == hkl)
return dwRet[uIndex];
hklprev = hkl;
dwLang = ((DWORD)hkl & 0xffff);
Aug 5, 2010
Aug 5, 2010
538
if (videodata->ime_uiless && LANG() == LANG_CHT) {
Aug 3, 2010
Aug 3, 2010
539
540
541
542
543
544
545
546
dwRet[0] = IMEID_CHT_VER_VISTA;
dwRet[1] = 0;
return dwRet[0];
}
if (hkl != CHT_HKL_NEW_PHONETIC
&& hkl != CHT_HKL_NEW_CHANG_JIE
&& hkl != CHT_HKL_NEW_QUICK
&& hkl != CHT_HKL_HK_CANTONESE
Aug 5, 2010
Aug 5, 2010
547
&& hkl != CHS_HKL) {
Aug 3, 2010
Aug 3, 2010
548
549
550
dwRet[0] = dwRet[1] = 0;
return dwRet[uIndex];
}
Aug 5, 2010
Aug 5, 2010
551
if (ImmGetIMEFileNameA(hkl, szTemp, sizeof(szTemp) - 1) <= 0) {
Aug 3, 2010
Aug 3, 2010
552
553
554
dwRet[0] = dwRet[1] = 0;
return dwRet[uIndex];
}
Aug 5, 2010
Aug 5, 2010
555
if (!videodata->GetReadingString) {
Aug 3, 2010
Aug 3, 2010
556
557
558
559
560
#define LCID_INVARIANT MAKELCID(MAKELANGID(LANG_ENGLISH, SUBLANG_ENGLISH_US), SORT_DEFAULT)
if (CompareStringA(LCID_INVARIANT, NORM_IGNORECASE, szTemp, -1, CHT_IMEFILENAME1, -1) != 2
&& CompareStringA(LCID_INVARIANT, NORM_IGNORECASE, szTemp, -1, CHT_IMEFILENAME2, -1) != 2
&& CompareStringA(LCID_INVARIANT, NORM_IGNORECASE, szTemp, -1, CHT_IMEFILENAME3, -1) != 2
&& CompareStringA(LCID_INVARIANT, NORM_IGNORECASE, szTemp, -1, CHS_IMEFILENAME1, -1) != 2
Aug 5, 2010
Aug 5, 2010
561
&& CompareStringA(LCID_INVARIANT, NORM_IGNORECASE, szTemp, -1, CHS_IMEFILENAME2, -1) != 2) {
Aug 3, 2010
Aug 3, 2010
562
563
564
565
566
dwRet[0] = dwRet[1] = 0;
return dwRet[uIndex];
}
#undef LCID_INVARIANT
dwVerSize = GetFileVersionInfoSizeA(szTemp, &dwVerHandle);
Aug 5, 2010
Aug 5, 2010
567
if (dwVerSize) {
Aug 3, 2010
Aug 3, 2010
568
lpVerBuffer = SDL_malloc(dwVerSize);
Aug 5, 2010
Aug 5, 2010
569
570
571
if (lpVerBuffer) {
if (GetFileVersionInfoA(szTemp, dwVerHandle, dwVerSize, lpVerBuffer)) {
if (VerQueryValueA(lpVerBuffer, "\\", &lpVerData, &cbVerData)) {
Aug 3, 2010
Aug 3, 2010
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
#define pVerFixedInfo ((VS_FIXEDFILEINFO FAR*)lpVerData)
DWORD dwVer = pVerFixedInfo->dwFileVersionMS;
dwVer = (dwVer & 0x00ff0000) << 8 | (dwVer & 0x000000ff) << 16;
if (videodata->GetReadingString ||
dwLang == LANG_CHT && (
dwVer == MAKEIMEVERSION(4, 2) ||
dwVer == MAKEIMEVERSION(4, 3) ||
dwVer == MAKEIMEVERSION(4, 4) ||
dwVer == MAKEIMEVERSION(5, 0) ||
dwVer == MAKEIMEVERSION(5, 1) ||
dwVer == MAKEIMEVERSION(5, 2) ||
dwVer == MAKEIMEVERSION(6, 0))
||
dwLang == LANG_CHS && (
dwVer == MAKEIMEVERSION(4, 1) ||
dwVer == MAKEIMEVERSION(4, 2) ||
Aug 5, 2010
Aug 5, 2010
588
dwVer == MAKEIMEVERSION(5, 3))) {
Aug 3, 2010
Aug 3, 2010
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
dwRet[0] = dwVer | dwLang;
dwRet[1] = pVerFixedInfo->dwFileVersionLS;
SDL_free(lpVerBuffer);
return dwRet[0];
}
#undef pVerFixedInfo
}
}
}
SDL_free(lpVerBuffer);
}
}
dwRet[0] = dwRet[1] = 0;
return dwRet[uIndex];
}
static void
IME_SetupAPI(SDL_VideoData *videodata)
{
char ime_file[MAX_PATH + 1];
Jan 25, 2011
Jan 25, 2011
609
void* hime = 0;
Aug 3, 2010
Aug 3, 2010
610
611
612
613
614
615
616
617
618
619
HKL hkl = 0;
videodata->GetReadingString = 0;
videodata->ShowReadingWindow = 0;
if (videodata->ime_uiless)
return;
hkl = videodata->ime_hkl;
if (ImmGetIMEFileNameA(hkl, ime_file, sizeof(ime_file) - 1) <= 0)
return;
Jan 25, 2011
Jan 25, 2011
620
hime = SDL_LoadObject(ime_file);
Aug 3, 2010
Aug 3, 2010
621
622
623
624
if (!hime)
return;
videodata->GetReadingString = (UINT (WINAPI *)(HIMC, UINT, LPWSTR, PINT, BOOL*, PUINT))
Jan 25, 2011
Jan 25, 2011
625
SDL_LoadFunction(hime, "GetReadingString");
Aug 3, 2010
Aug 3, 2010
626
videodata->ShowReadingWindow = (BOOL (WINAPI *)(HIMC, BOOL))
Jan 25, 2011
Jan 25, 2011
627
SDL_LoadFunction(hime, "ShowReadingWindow");
Aug 3, 2010
Aug 3, 2010
628
Aug 5, 2010
Aug 5, 2010
629
if (videodata->ShowReadingWindow) {
Aug 3, 2010
Aug 3, 2010
630
HIMC himc = ImmGetContext(videodata->ime_hwnd_current);
Aug 5, 2010
Aug 5, 2010
631
if (himc) {
Aug 3, 2010
Aug 3, 2010
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
videodata->ShowReadingWindow(himc, FALSE);
ImmReleaseContext(videodata->ime_hwnd_current, himc);
}
}
}
static void
IME_SetWindow(SDL_VideoData* videodata, HWND hwnd)
{
videodata->ime_hwnd_current = hwnd;
if (videodata->ime_threadmgr) {
struct ITfDocumentMgr *document_mgr = 0;
if (SUCCEEDED(videodata->ime_threadmgr->lpVtbl->AssociateFocus(videodata->ime_threadmgr, hwnd, NULL, &document_mgr))) {
if (document_mgr)
document_mgr->lpVtbl->Release(document_mgr);
}
}
}
static void
IME_UpdateInputLocale(SDL_VideoData *videodata)
{
Aug 5, 2010
Aug 5, 2010
654
static HKL hklprev = 0;
Aug 3, 2010
Aug 3, 2010
655
videodata->ime_hkl = GetKeyboardLayout(0);
Aug 5, 2010
Aug 5, 2010
656
if (hklprev == videodata->ime_hkl)
Aug 3, 2010
Aug 3, 2010
657
658
return;
Aug 5, 2010
Aug 5, 2010
659
hklprev = videodata->ime_hkl;
Nov 24, 2010
Nov 24, 2010
660
switch (PRIMLANG()) {
Nov 23, 2010
Nov 23, 2010
661
662
663
664
665
666
667
668
669
670
671
672
673
case LANG_CHINESE:
videodata->ime_candvertical = SDL_TRUE;
if (SUBLANG() == SUBLANG_CHINESE_SIMPLIFIED)
videodata->ime_candvertical = SDL_FALSE;
break;
case LANG_JAPANESE:
videodata->ime_candvertical = SDL_TRUE;
break;
case LANG_KOREAN:
videodata->ime_candvertical = SDL_FALSE;
break;
}
Aug 3, 2010
Aug 3, 2010
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
}
static void
IME_ClearComposition(SDL_VideoData *videodata)
{
HIMC himc = 0;
if (!videodata->ime_initialized)
return;
himc = ImmGetContext(videodata->ime_hwnd_current);
if (!himc)
return;
ImmNotifyIME(himc, NI_COMPOSITIONSTR, CPS_CANCEL, 0);
if (videodata->ime_uiless)
ImmSetCompositionString(himc, SCS_SETSTR, TEXT(""), sizeof(TCHAR), TEXT(""), sizeof(TCHAR));
ImmNotifyIME(himc, NI_CLOSECANDIDATE, 0, 0);
ImmReleaseContext(videodata->ime_hwnd_current, himc);
SDL_SendEditingText("", 0, 0);
}
static void
IME_GetCompositionString(SDL_VideoData *videodata, HIMC himc, DWORD string)
{
Aug 5, 2010
Aug 5, 2010
699
700
701
LONG length = ImmGetCompositionStringW(himc, string, videodata->ime_composition, sizeof(videodata->ime_composition));
if (length < 0)
length = 0;
Aug 3, 2010
Aug 3, 2010
702
Aug 5, 2010
Aug 5, 2010
703
length /= sizeof(videodata->ime_composition[0]);
Aug 3, 2010
Aug 3, 2010
704
videodata->ime_cursor = LOWORD(ImmGetCompositionStringW(himc, GCS_CURSORPOS, 0, 0));
Aug 5, 2010
Aug 5, 2010
705
if (videodata->ime_composition[videodata->ime_cursor] == 0x3000) {
Aug 3, 2010
Aug 3, 2010
706
int i;
Aug 5, 2010
Aug 5, 2010
707
for (i = videodata->ime_cursor + 1; i < length; ++i)
Aug 3, 2010
Aug 3, 2010
708
709
videodata->ime_composition[i - 1] = videodata->ime_composition[i];
Aug 5, 2010
Aug 5, 2010
710
--length;
Aug 3, 2010
Aug 3, 2010
711
}
Aug 5, 2010
Aug 5, 2010
712
videodata->ime_composition[length] = 0;
Aug 3, 2010
Aug 3, 2010
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
}
static void
IME_SendInputEvent(SDL_VideoData *videodata)
{
char *s = 0;
s = WIN_StringToUTF8(videodata->ime_composition);
SDL_SendKeyboardText(s);
SDL_free(s);
videodata->ime_composition[0] = 0;
videodata->ime_readingstring[0] = 0;
videodata->ime_cursor = 0;
}
static void
IME_SendEditingEvent(SDL_VideoData *videodata)
{
char *s = 0;
Aug 5, 2010
Aug 5, 2010
732
733
734
WCHAR buffer[SDL_TEXTEDITINGEVENT_TEXT_SIZE];
buffer[0] = 0;
if (videodata->ime_readingstring[0]) {
Aug 3, 2010
Aug 3, 2010
735
size_t len = SDL_min(SDL_wcslen(videodata->ime_composition), (size_t)videodata->ime_cursor);
Aug 5, 2010
Aug 5, 2010
736
737
738
SDL_wcslcpy(buffer, videodata->ime_composition, len + 1);
SDL_wcslcat(buffer, videodata->ime_readingstring, sizeof(buffer));
SDL_wcslcat(buffer, &videodata->ime_composition[len], sizeof(buffer) - len);
Aug 3, 2010
Aug 3, 2010
739
}
Aug 5, 2010
Aug 5, 2010
740
741
else {
SDL_wcslcpy(buffer, videodata->ime_composition, sizeof(videodata->ime_composition));
Aug 3, 2010
Aug 3, 2010
742
}
Aug 5, 2010
Aug 5, 2010
743
s = WIN_StringToUTF8(buffer);
Aug 3, 2010
Aug 3, 2010
744
745
746
747
SDL_SendEditingText(s, videodata->ime_cursor + SDL_wcslen(videodata->ime_readingstring), 0);
SDL_free(s);
}
Nov 23, 2010
Nov 23, 2010
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
static void
IME_AddCandidate(SDL_VideoData *videodata, UINT i, LPCWSTR candidate)
{
LPWSTR dst = videodata->ime_candidates[i];
*dst++ = (WCHAR)(TEXT('0') + ((i + videodata->ime_candlistindexbase) % 10));
if (videodata->ime_candvertical)
*dst++ = TEXT(' ');
while (*candidate && (SDL_arraysize(videodata->ime_candidates[i]) > (dst - videodata->ime_candidates[i])))
*dst++ = *candidate++;
*dst = (WCHAR)'\0';
}
static void
IME_GetCandidateList(HIMC himc, SDL_VideoData *videodata)
{
LPCANDIDATELIST cand_list = 0;
DWORD size = ImmGetCandidateListW(himc, 0, 0, 0);
Nov 24, 2010
Nov 24, 2010
767
if (size) {
Nov 23, 2010
Nov 23, 2010
768
cand_list = (LPCANDIDATELIST)SDL_malloc(size);
Nov 24, 2010
Nov 24, 2010
769
if (cand_list) {
Nov 23, 2010
Nov 23, 2010
770
size = ImmGetCandidateListW(himc, 0, cand_list, size);
Nov 24, 2010
Nov 24, 2010
771
if (size) {
Nov 23, 2010
Nov 23, 2010
772
773
774
775
776
777
int i = 0;
int j = 0;
int page_start = 0;
videodata->ime_candsel = cand_list->dwSelection;
videodata->ime_candcount = cand_list->dwCount;
Nov 24, 2010
Nov 24, 2010
778
if (LANG() == LANG_CHS && IME_GetId(videodata, 0)) {
Nov 23, 2010
Nov 23, 2010
779
780
781
782
const UINT maxcandchar = 18;
UINT i = 0;
UINT cchars = 0;
Nov 24, 2010
Nov 24, 2010
783
for (; i < videodata->ime_candcount; ++i) {
Nov 23, 2010
Nov 23, 2010
784
UINT len = SDL_wcslen((LPWSTR)((DWORD)cand_list + cand_list->dwOffset[i])) + 1;
Nov 24, 2010
Nov 24, 2010
785
if (len + cchars > maxcandchar) {
Nov 23, 2010
Nov 23, 2010
786
787
788
789
790
791
if (i > cand_list->dwSelection)
break;
page_start = i;
cchars = len;
}
Nov 24, 2010
Nov 24, 2010
792
else {
Nov 23, 2010
Nov 23, 2010
793
794
795
796
797
cchars += len;
}
}
videodata->ime_candpgsize = i - page_start;
}
Nov 24, 2010
Nov 24, 2010
798
else {
Nov 23, 2010
Nov 23, 2010
799
800
801
802
videodata->ime_candpgsize = SDL_min(cand_list->dwPageSize, MAX_CANDLIST);
page_start = (cand_list->dwSelection / videodata->ime_candpgsize) * videodata->ime_candpgsize;
}
SDL_memset(&videodata->ime_candidates, 0, sizeof(videodata->ime_candidates));
Nov 24, 2010
Nov 24, 2010
803
for (i = page_start, j = 0; (DWORD)i < cand_list->dwCount && j < (int)videodata->ime_candpgsize; i++, j++) {
Nov 23, 2010
Nov 23, 2010
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
LPCWSTR candidate = (LPCWSTR)((DWORD)cand_list + cand_list->dwOffset[i]);
IME_AddCandidate(videodata, j, candidate);
}
if (PRIMLANG() == LANG_KOREAN || (PRIMLANG() == LANG_CHT && !IME_GetId(videodata, 0)))
videodata->ime_candsel = -1;
}
SDL_free(cand_list);
}
}
}
static void
IME_ShowCandidateList(SDL_VideoData *videodata)
{
videodata->ime_dirty = SDL_TRUE;
videodata->ime_candlist = SDL_TRUE;
IME_DestroyTextures(videodata);
IME_SendEditingEvent(videodata);
}
static void
IME_HideCandidateList(SDL_VideoData *videodata)
{
videodata->ime_dirty = SDL_FALSE;
videodata->ime_candlist = SDL_FALSE;
IME_DestroyTextures(videodata);
IME_SendEditingEvent(videodata);
}
Jul 12, 2010
Jul 12, 2010
834
835
836
837
838
839
840
841
SDL_bool
IME_HandleMessage(HWND hwnd, UINT msg, WPARAM wParam, LPARAM *lParam, SDL_VideoData *videodata)
{
SDL_bool trap = SDL_FALSE;
HIMC himc = 0;
if (!videodata->ime_initialized || !videodata->ime_available || !videodata->ime_enabled)
return SDL_FALSE;
Nov 24, 2010
Nov 24, 2010
842
switch (msg) {
Jul 12, 2010
Jul 12, 2010
843
case WM_INPUTLANGCHANGE:
Nov 23, 2010
Nov 23, 2010
844
IME_InputLangChanged(videodata);
Jul 12, 2010
Jul 12, 2010
845
846
847
848
849
850
851
852
853
854
break;
case WM_IME_SETCONTEXT:
*lParam = 0;
break;
case WM_IME_STARTCOMPOSITION:
trap = SDL_TRUE;
break;
case WM_IME_COMPOSITION:
trap = SDL_TRUE;
himc = ImmGetContext(hwnd);
Aug 5, 2010
Aug 5, 2010
855
if (*lParam & GCS_RESULTSTR) {
Aug 3, 2010
Aug 3, 2010
856
857
IME_GetCompositionString(videodata, himc, GCS_RESULTSTR);
IME_SendInputEvent(videodata);
Jul 12, 2010
Jul 12, 2010
858
}
Aug 5, 2010
Aug 5, 2010
859
if (*lParam & GCS_COMPSTR) {
Aug 3, 2010
Aug 3, 2010
860
861
862
863
864
if (!videodata->ime_uiless)
videodata->ime_readingstring[0] = 0;
IME_GetCompositionString(videodata, himc, GCS_COMPSTR);
IME_SendEditingEvent(videodata);
Jul 12, 2010
Jul 12, 2010
865
866
867
868
}
ImmReleaseContext(hwnd, himc);
break;
case WM_IME_ENDCOMPOSITION:
Aug 3, 2010
Aug 3, 2010
869
870
871
872
videodata->ime_composition[0] = 0;
videodata->ime_readingstring[0] = 0;
videodata->ime_cursor = 0;
SDL_SendEditingText("", 0, 0);
Jul 12, 2010
Jul 12, 2010
873
874
break;
case WM_IME_NOTIFY:
Nov 24, 2010
Nov 24, 2010
875
switch (wParam) {
Jul 12, 2010
Jul 12, 2010
876
877
case IMN_SETCONVERSIONMODE:
case IMN_SETOPENSTATUS:
Aug 3, 2010
Aug 3, 2010
878
IME_UpdateInputLocale(videodata);
Jul 12, 2010
Jul 12, 2010
879
880
881
break;
case IMN_OPENCANDIDATE:
case IMN_CHANGECANDIDATE:
Nov 23, 2010
Nov 23, 2010
882
883
884
if (videodata->ime_uiless)
break;
Jul 12, 2010
Jul 12, 2010
885
trap = SDL_TRUE;
Nov 23, 2010
Nov 23, 2010
886
887
888
889
890
891
892
IME_ShowCandidateList(videodata);
himc = ImmGetContext(hwnd);
if (!himc)
break;
IME_GetCandidateList(himc, videodata);
ImmReleaseContext(hwnd, himc);
Jul 12, 2010
Jul 12, 2010
893
894
895
break;
case IMN_CLOSECANDIDATE:
trap = SDL_TRUE;
Nov 23, 2010
Nov 23, 2010
896
IME_HideCandidateList(videodata);
Jul 12, 2010
Jul 12, 2010
897
898
break;
case IMN_PRIVATE:
Aug 3, 2010
Aug 3, 2010
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
{
DWORD dwId = IME_GetId(videodata, 0);
IME_GetReadingString(videodata, hwnd);
switch (dwId)
{
case IMEID_CHT_VER42:
case IMEID_CHT_VER43:
case IMEID_CHT_VER44:
case IMEID_CHS_VER41:
case IMEID_CHS_VER42:
if (*lParam == 1 || *lParam == 2)
trap = SDL_TRUE;
break;
case IMEID_CHT_VER50:
case IMEID_CHT_VER51:
case IMEID_CHT_VER52:
case IMEID_CHT_VER60:
case IMEID_CHS_VER53:
if (*lParam == 16
|| *lParam == 17
|| *lParam == 26
|| *lParam == 27
|| *lParam == 28)
trap = SDL_TRUE;
break;
}
}
Jul 12, 2010
Jul 12, 2010
927
928
929
930
931
932
933
934
935
936
break;
default:
trap = SDL_TRUE;
break;
}
break;
}
return trap;
}
Nov 23, 2010
Nov 23, 2010
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
static void
IME_CloseCandidateList(SDL_VideoData *videodata)
{
IME_HideCandidateList(videodata);
videodata->ime_candcount = 0;
SDL_memset(videodata->ime_candidates, 0, sizeof(videodata->ime_candidates));
}
static void
UILess_GetCandidateList(SDL_VideoData *videodata, ITfCandidateListUIElement *pcandlist)
{
UINT selection = 0;
UINT count = 0;
UINT page = 0;
UINT pgcount = 0;
DWORD pgstart = 0;
DWORD pgsize = 0;
UINT i, j;
pcandlist->lpVtbl->GetSelection(pcandlist, &selection);
pcandlist->lpVtbl->GetCount(pcandlist, &count);
pcandlist->lpVtbl->GetCurrentPage(pcandlist, &page);
videodata->ime_candsel = selection;
videodata->ime_candcount = count;
IME_ShowCandidateList(videodata);
pcandlist->lpVtbl->GetPageIndex(pcandlist, 0, 0, &pgcount);
Nov 24, 2010
Nov 24, 2010
964
if (pgcount > 0) {
Nov 23, 2010
Nov 23, 2010
965
UINT *idxlist = SDL_malloc(sizeof(UINT) * pgcount);
Nov 24, 2010
Nov 24, 2010
966
if (idxlist) {
Nov 23, 2010
Nov 23, 2010
967
968
969
970
971
972
973
974
975
976
977
978
979
980
pcandlist->lpVtbl->GetPageIndex(pcandlist, idxlist, pgcount, &pgcount);
pgstart = idxlist[page];
if (page < pgcount - 1)
pgsize = SDL_min(count, idxlist[page + 1]) - pgstart;
else
pgsize = count - pgstart;
SDL_free(idxlist);
}
}
videodata->ime_candpgsize = SDL_min(pgsize, MAX_CANDLIST);
videodata->ime_candsel = videodata->ime_candsel - pgstart;
SDL_memset(videodata->ime_candidates, 0, sizeof(videodata->ime_candidates));
Nov 24, 2010
Nov 24, 2010
981
for (i = pgstart, j = 0; (DWORD)i < count && j < videodata->ime_candpgsize; i++, j++) {
Nov 23, 2010
Nov 23, 2010
982
BSTR bstr;
Nov 24, 2010
Nov 24, 2010
983
984
if (SUCCEEDED(pcandlist->lpVtbl->GetString(pcandlist, i, &bstr))) {
if (bstr) {
Nov 23, 2010
Nov 23, 2010
985
986
987
988
989
990
991
992
993
IME_AddCandidate(videodata, j, bstr);
SysFreeString(bstr);
}
}
}
if (PRIMLANG() == LANG_KOREAN)
videodata->ime_candsel = -1;
}
Aug 3, 2010
Aug 3, 2010
994
995
996
997
998
999
1000
STDMETHODIMP_(ULONG) TSFSink_AddRef(TSFSink *sink)
{
return ++sink->refcount;
}
STDMETHODIMP_(ULONG)TSFSink_Release(TSFSink *sink)
{