comparison src/video/win32/SDL_win32keyboard.c @ 4880:27c458e4ae31

Update VS2010 project to add new files; update new files so code builds on Win32/Win64
author Andreas Schiffler <aschiffler@ferzkopp.net>
date Mon, 23 Aug 2010 23:44:28 -0700
parents 518d1679d2d0
children
comparison
equal deleted inserted replaced
4864:ebcb4988b16f 4880:27c458e4ae31
26 #include "../../events/SDL_keyboard_c.h" 26 #include "../../events/SDL_keyboard_c.h"
27 #include "../../events/scancodes_win32.h" 27 #include "../../events/scancodes_win32.h"
28 28
29 #include <imm.h> 29 #include <imm.h>
30 #include <oleauto.h> 30 #include <oleauto.h>
31 #include <winver.h>
31 32
32 static void IME_Init(SDL_VideoData *videodata, HWND hwnd); 33 static void IME_Init(SDL_VideoData *videodata, HWND hwnd);
33 static void IME_Enable(SDL_VideoData *videodata, HWND hwnd); 34 static void IME_Enable(SDL_VideoData *videodata, HWND hwnd);
34 static void IME_Disable(SDL_VideoData *videodata, HWND hwnd); 35 static void IME_Disable(SDL_VideoData *videodata, HWND hwnd);
35 static void IME_Quit(SDL_VideoData *videodata); 36 static void IME_Quit(SDL_VideoData *videodata);
244 return; 245 return;
245 246
246 videodata->ime_hwnd_main = hwnd; 247 videodata->ime_hwnd_main = hwnd;
247 if (SUCCEEDED(CoInitializeEx(NULL, COINIT_APARTMENTTHREADED))) { 248 if (SUCCEEDED(CoInitializeEx(NULL, COINIT_APARTMENTTHREADED))) {
248 videodata->ime_com_initialized = SDL_TRUE; 249 videodata->ime_com_initialized = SDL_TRUE;
249 CoCreateInstance(&CLSID_TF_ThreadMgr, NULL, CLSCTX_INPROC_SERVER, &IID_ITfThreadMgr, &videodata->ime_threadmgr); 250 CoCreateInstance(&CLSID_TF_ThreadMgr, NULL, CLSCTX_INPROC_SERVER, &IID_ITfThreadMgr, (LPVOID *)&videodata->ime_threadmgr);
250 } 251 }
251 videodata->ime_initialized = SDL_TRUE; 252 videodata->ime_initialized = SDL_TRUE;
252 videodata->ime_himm32 = LoadLibraryA("imm32.dll"); 253 videodata->ime_himm32 = LoadLibraryA("imm32.dll");
253 if (!videodata->ime_himm32) { 254 if (!videodata->ime_himm32) {
254 videodata->ime_available = SDL_FALSE; 255 videodata->ime_available = SDL_FALSE;
258 videodata->ImmUnlockIMC = (BOOL (WINAPI *)(HIMC))GetProcAddress(videodata->ime_himm32, "ImmUnlockIMC"); 259 videodata->ImmUnlockIMC = (BOOL (WINAPI *)(HIMC))GetProcAddress(videodata->ime_himm32, "ImmUnlockIMC");
259 videodata->ImmLockIMCC = (LPVOID (WINAPI *)(HIMCC))GetProcAddress(videodata->ime_himm32, "ImmLockIMCC"); 260 videodata->ImmLockIMCC = (LPVOID (WINAPI *)(HIMCC))GetProcAddress(videodata->ime_himm32, "ImmLockIMCC");
260 videodata->ImmUnlockIMCC = (BOOL (WINAPI *)(HIMCC))GetProcAddress(videodata->ime_himm32, "ImmUnlockIMCC"); 261 videodata->ImmUnlockIMCC = (BOOL (WINAPI *)(HIMCC))GetProcAddress(videodata->ime_himm32, "ImmUnlockIMCC");
261 262
262 IME_SetWindow(videodata, hwnd); 263 IME_SetWindow(videodata, hwnd);
264 #ifdef _WIN32_WCE
263 videodata->ime_himc = ImmGetContext(hwnd); 265 videodata->ime_himc = ImmGetContext(hwnd);
264 ImmReleaseContext(hwnd, videodata->ime_himc); 266 ImmReleaseContext(hwnd, videodata->ime_himc);
267 #endif
265 if (!videodata->ime_himc) { 268 if (!videodata->ime_himc) {
266 videodata->ime_available = SDL_FALSE; 269 videodata->ime_available = SDL_FALSE;
267 IME_Disable(videodata, hwnd); 270 IME_Disable(videodata, hwnd);
268 return; 271 return;
269 } 272 }
283 286
284 if (!videodata->ime_available) { 287 if (!videodata->ime_available) {
285 IME_Disable(videodata, hwnd); 288 IME_Disable(videodata, hwnd);
286 return; 289 return;
287 } 290 }
288 if (videodata->ime_hwnd_current == videodata->ime_hwnd_main) 291 #ifdef _WIN32_WCE
292 if (videodata->ime_hwnd_current == videodata->ime_hwnd_main)
289 ImmAssociateContext(videodata->ime_hwnd_current, videodata->ime_himc); 293 ImmAssociateContext(videodata->ime_hwnd_current, videodata->ime_himc);
294 #endif
290 295
291 videodata->ime_enabled = SDL_TRUE; 296 videodata->ime_enabled = SDL_TRUE;
292 IME_UpdateInputLocale(videodata); 297 IME_UpdateInputLocale(videodata);
293 UILess_EnableUIUpdates(videodata); 298 UILess_EnableUIUpdates(videodata);
294 } 299 }
298 { 303 {
299 if (!videodata->ime_initialized || !videodata->ime_hwnd_current) 304 if (!videodata->ime_initialized || !videodata->ime_hwnd_current)
300 return; 305 return;
301 306
302 IME_ClearComposition(videodata); 307 IME_ClearComposition(videodata);
308 #ifdef _WIN32_WCE
303 if (videodata->ime_hwnd_current == videodata->ime_hwnd_main) 309 if (videodata->ime_hwnd_current == videodata->ime_hwnd_main)
304 ImmAssociateContext(videodata->ime_hwnd_current, NULL); 310 ImmAssociateContext(videodata->ime_hwnd_current, NULL);
311 #endif
305 312
306 videodata->ime_enabled = SDL_FALSE; 313 videodata->ime_enabled = SDL_FALSE;
307 UILess_DisableUIUpdates(videodata); 314 UILess_DisableUIUpdates(videodata);
308 } 315 }
309 316
312 { 319 {
313 if (!videodata->ime_initialized) 320 if (!videodata->ime_initialized)
314 return; 321 return;
315 322
316 UILess_ReleaseSinks(videodata); 323 UILess_ReleaseSinks(videodata);
324 #ifdef _WIN32_WCE
317 if (videodata->ime_hwnd_main) 325 if (videodata->ime_hwnd_main)
318 ImmAssociateContext(videodata->ime_hwnd_main, videodata->ime_himc); 326 ImmAssociateContext(videodata->ime_hwnd_main, videodata->ime_himc);
327 #endif
319 328
320 videodata->ime_hwnd_main = 0; 329 videodata->ime_hwnd_main = 0;
321 videodata->ime_himc = 0; 330 videodata->ime_himc = 0;
322 if (videodata->ime_himm32) { 331 if (videodata->ime_himm32) {
323 FreeLibrary(videodata->ime_himm32); 332 FreeLibrary(videodata->ime_himm32);
356 } 365 }
357 id = IME_GetId(videodata, 0); 366 id = IME_GetId(videodata, 0);
358 if (!id) 367 if (!id)
359 return; 368 return;
360 369
370 #ifdef _WIN32_WCE
361 himc = ImmGetContext(hwnd); 371 himc = ImmGetContext(hwnd);
362 if (!himc) 372 if (!himc)
363 return; 373 return;
374 #endif
364 375
365 if (videodata->GetReadingString) { 376 if (videodata->GetReadingString) {
366 len = videodata->GetReadingString(himc, 0, 0, &err, &vertical, &maxuilen); 377 len = videodata->GetReadingString(himc, 0, 0, &err, &vertical, &maxuilen);
367 if (len) { 378 if (len) {
368 if (len > SDL_arraysize(buffer)) 379 if (len > SDL_arraysize(buffer))
429 SDL_wcslcpy(videodata->ime_readingstring, s, len + 1); 440 SDL_wcslcpy(videodata->ime_readingstring, s, len + 1);
430 441
431 videodata->ImmUnlockIMCC(lpimc->hPrivate); 442 videodata->ImmUnlockIMCC(lpimc->hPrivate);
432 videodata->ImmUnlockIMC(himc); 443 videodata->ImmUnlockIMC(himc);
433 } 444 }
445 #ifdef _WIN32_WCE
434 ImmReleaseContext(hwnd, himc); 446 ImmReleaseContext(hwnd, himc);
447 #endif
435 IME_SendEditingEvent(videodata); 448 IME_SendEditingEvent(videodata);
436 } 449 }
437 450
438 static void 451 static void
439 IME_InputLangChanged(SDL_VideoData *videodata) 452 IME_InputLangChanged(SDL_VideoData *videodata)
443 IME_UpdateInputLocale(videodata); 456 IME_UpdateInputLocale(videodata);
444 IME_SetupAPI(videodata); 457 IME_SetupAPI(videodata);
445 if (lang != PRIMLANG()) { 458 if (lang != PRIMLANG()) {
446 IME_ClearComposition(videodata); 459 IME_ClearComposition(videodata);
447 } 460 }
461 #ifdef _WIN32_WCE
448 hwndime = ImmGetDefaultIMEWnd(videodata->ime_hwnd_current); 462 hwndime = ImmGetDefaultIMEWnd(videodata->ime_hwnd_current);
449 if (hwndime) { 463 if (hwndime) {
450 SendMessageA(hwndime, WM_IME_CONTROL, IMC_OPENSTATUSWINDOW, 0); 464 SendMessageA(hwndime, WM_IME_CONTROL, IMC_OPENSTATUSWINDOW, 0);
451 SendMessageA(hwndime, WM_IME_CONTROL, IMC_CLOSESTATUSWINDOW, 0); 465 SendMessageA(hwndime, WM_IME_CONTROL, IMC_CLOSESTATUSWINDOW, 0);
452 } 466 }
467 #endif
453 } 468 }
454 469
455 static DWORD 470 static DWORD
456 IME_GetId(SDL_VideoData *videodata, UINT uIndex) 471 IME_GetId(SDL_VideoData *videodata, UINT uIndex)
457 { 472 {
485 && hkl != CHT_HKL_HK_CANTONESE 500 && hkl != CHT_HKL_HK_CANTONESE
486 && hkl != CHS_HKL) { 501 && hkl != CHS_HKL) {
487 dwRet[0] = dwRet[1] = 0; 502 dwRet[0] = dwRet[1] = 0;
488 return dwRet[uIndex]; 503 return dwRet[uIndex];
489 } 504 }
505 #ifdef _WIN32_WCE
490 if (ImmGetIMEFileNameA(hkl, szTemp, sizeof(szTemp) - 1) <= 0) { 506 if (ImmGetIMEFileNameA(hkl, szTemp, sizeof(szTemp) - 1) <= 0) {
491 dwRet[0] = dwRet[1] = 0; 507 dwRet[0] = dwRet[1] = 0;
492 return dwRet[uIndex]; 508 return dwRet[uIndex];
493 } 509 }
494 if (!videodata->GetReadingString) { 510 #endif
511 if (!videodata->GetReadingString) {
495 #define LCID_INVARIANT MAKELCID(MAKELANGID(LANG_ENGLISH, SUBLANG_ENGLISH_US), SORT_DEFAULT) 512 #define LCID_INVARIANT MAKELCID(MAKELANGID(LANG_ENGLISH, SUBLANG_ENGLISH_US), SORT_DEFAULT)
496 if (CompareStringA(LCID_INVARIANT, NORM_IGNORECASE, szTemp, -1, CHT_IMEFILENAME1, -1) != 2 513 if (CompareStringA(LCID_INVARIANT, NORM_IGNORECASE, szTemp, -1, CHT_IMEFILENAME1, -1) != 2
497 && CompareStringA(LCID_INVARIANT, NORM_IGNORECASE, szTemp, -1, CHT_IMEFILENAME2, -1) != 2 514 && CompareStringA(LCID_INVARIANT, NORM_IGNORECASE, szTemp, -1, CHT_IMEFILENAME2, -1) != 2
498 && CompareStringA(LCID_INVARIANT, NORM_IGNORECASE, szTemp, -1, CHT_IMEFILENAME3, -1) != 2 515 && CompareStringA(LCID_INVARIANT, NORM_IGNORECASE, szTemp, -1, CHT_IMEFILENAME3, -1) != 2
499 && CompareStringA(LCID_INVARIANT, NORM_IGNORECASE, szTemp, -1, CHS_IMEFILENAME1, -1) != 2 516 && CompareStringA(LCID_INVARIANT, NORM_IGNORECASE, szTemp, -1, CHS_IMEFILENAME1, -1) != 2
551 videodata->ShowReadingWindow = 0; 568 videodata->ShowReadingWindow = 0;
552 if (videodata->ime_uiless) 569 if (videodata->ime_uiless)
553 return; 570 return;
554 571
555 hkl = videodata->ime_hkl; 572 hkl = videodata->ime_hkl;
556 if (ImmGetIMEFileNameA(hkl, ime_file, sizeof(ime_file) - 1) <= 0) 573 #ifdef _WIN32_WCE
557 return; 574 if (ImmGetIMEFileNameA(hkl, ime_file, sizeof(ime_file) - 1) <= 0)
575 return;
576 #endif
558 577
559 hime = LoadLibraryA(ime_file); 578 hime = LoadLibraryA(ime_file);
560 if (!hime) 579 if (!hime)
561 return; 580 return;
562 581
563 videodata->GetReadingString = (UINT (WINAPI *)(HIMC, UINT, LPWSTR, PINT, BOOL*, PUINT)) 582 videodata->GetReadingString = (UINT (WINAPI *)(HIMC, UINT, LPWSTR, PINT, BOOL*, PUINT))
564 GetProcAddress(hime, "GetReadingString"); 583 GetProcAddress(hime, "GetReadingString");
565 videodata->ShowReadingWindow = (BOOL (WINAPI *)(HIMC, BOOL)) 584 videodata->ShowReadingWindow = (BOOL (WINAPI *)(HIMC, BOOL))
566 GetProcAddress(hime, "ShowReadingWindow"); 585 GetProcAddress(hime, "ShowReadingWindow");
567 586
587 #ifdef _WIN32_WCE
568 if (videodata->ShowReadingWindow) { 588 if (videodata->ShowReadingWindow) {
569 HIMC himc = ImmGetContext(videodata->ime_hwnd_current); 589 HIMC himc = ImmGetContext(videodata->ime_hwnd_current);
570 if (himc) { 590 if (himc) {
571 videodata->ShowReadingWindow(himc, FALSE); 591 videodata->ShowReadingWindow(himc, FALSE);
572 ImmReleaseContext(videodata->ime_hwnd_current, himc); 592 ImmReleaseContext(videodata->ime_hwnd_current, himc);
573 } 593 }
574 } 594 }
595 #endif
575 } 596 }
576 597
577 static void 598 static void
578 IME_SetWindow(SDL_VideoData* videodata, HWND hwnd) 599 IME_SetWindow(SDL_VideoData* videodata, HWND hwnd)
579 { 600 {
603 { 624 {
604 HIMC himc = 0; 625 HIMC himc = 0;
605 if (!videodata->ime_initialized) 626 if (!videodata->ime_initialized)
606 return; 627 return;
607 628
629 #ifdef _WIN32_WCE
608 himc = ImmGetContext(videodata->ime_hwnd_current); 630 himc = ImmGetContext(videodata->ime_hwnd_current);
609 if (!himc) 631 if (!himc)
610 return; 632 return;
611 633
612 ImmNotifyIME(himc, NI_COMPOSITIONSTR, CPS_CANCEL, 0); 634 ImmNotifyIME(himc, NI_COMPOSITIONSTR, CPS_CANCEL, 0);
613 if (videodata->ime_uiless) 635 if (videodata->ime_uiless)
614 ImmSetCompositionString(himc, SCS_SETSTR, TEXT(""), sizeof(TCHAR), TEXT(""), sizeof(TCHAR)); 636 ImmSetCompositionString(himc, SCS_SETSTR, TEXT(""), sizeof(TCHAR), TEXT(""), sizeof(TCHAR));
615 637
616 ImmNotifyIME(himc, NI_CLOSECANDIDATE, 0, 0); 638 ImmNotifyIME(himc, NI_CLOSECANDIDATE, 0, 0);
617 ImmReleaseContext(videodata->ime_hwnd_current, himc); 639 ImmReleaseContext(videodata->ime_hwnd_current, himc);
640 #endif
618 SDL_SendEditingText("", 0, 0); 641 SDL_SendEditingText("", 0, 0);
619 } 642 }
620 643
621 static void 644 static void
622 IME_ClearEditing(SDL_VideoData *videodata) 645 IME_ClearEditing(SDL_VideoData *videodata)
695 case WM_IME_STARTCOMPOSITION: 718 case WM_IME_STARTCOMPOSITION:
696 trap = SDL_TRUE; 719 trap = SDL_TRUE;
697 break; 720 break;
698 case WM_IME_COMPOSITION: 721 case WM_IME_COMPOSITION:
699 trap = SDL_TRUE; 722 trap = SDL_TRUE;
723 #ifdef _WIN32_WCE
700 himc = ImmGetContext(hwnd); 724 himc = ImmGetContext(hwnd);
701 if (*lParam & GCS_RESULTSTR) { 725 if (*lParam & GCS_RESULTSTR) {
702 IME_GetCompositionString(videodata, himc, GCS_RESULTSTR); 726 IME_GetCompositionString(videodata, himc, GCS_RESULTSTR);
703 IME_SendInputEvent(videodata); 727 IME_SendInputEvent(videodata);
704 } 728 }
708 732
709 IME_GetCompositionString(videodata, himc, GCS_COMPSTR); 733 IME_GetCompositionString(videodata, himc, GCS_COMPSTR);
710 IME_SendEditingEvent(videodata); 734 IME_SendEditingEvent(videodata);
711 } 735 }
712 ImmReleaseContext(hwnd, himc); 736 ImmReleaseContext(hwnd, himc);
737 #endif
713 break; 738 break;
714 case WM_IME_ENDCOMPOSITION: 739 case WM_IME_ENDCOMPOSITION:
715 videodata->ime_composition[0] = 0; 740 videodata->ime_composition[0] = 0;
716 videodata->ime_readingstring[0] = 0; 741 videodata->ime_readingstring[0] = 0;
717 videodata->ime_cursor = 0; 742 videodata->ime_cursor = 0;