Mercurial > sdl-ios-xcode
comparison src/video/win32/SDL_win32keyboard.c @ 4760:c40027ee6d47
Updated to fit SDL style a little more.
author | dewyatt |
---|---|
date | Wed, 04 Aug 2010 23:17:12 -0400 |
parents | 863ba7d1f029 |
children | 518d1679d2d0 |
comparison
equal
deleted
inserted
replaced
4759:863ba7d1f029 | 4760:c40027ee6d47 |
---|---|
318 if (videodata->ime_hwnd_main) | 318 if (videodata->ime_hwnd_main) |
319 ImmAssociateContext(videodata->ime_hwnd_main, videodata->ime_himc); | 319 ImmAssociateContext(videodata->ime_hwnd_main, videodata->ime_himc); |
320 | 320 |
321 videodata->ime_hwnd_main = 0; | 321 videodata->ime_hwnd_main = 0; |
322 videodata->ime_himc = 0; | 322 videodata->ime_himc = 0; |
323 if (videodata->ime_himm32) | 323 if (videodata->ime_himm32) { |
324 { | |
325 FreeLibrary(videodata->ime_himm32); | 324 FreeLibrary(videodata->ime_himm32); |
326 videodata->ime_himm32 = 0; | 325 videodata->ime_himm32 = 0; |
327 } | 326 } |
328 if (videodata->ime_threadmgr) | 327 if (videodata->ime_threadmgr) { |
329 { | |
330 videodata->ime_threadmgr->lpVtbl->Release(videodata->ime_threadmgr); | 328 videodata->ime_threadmgr->lpVtbl->Release(videodata->ime_threadmgr); |
331 videodata->ime_threadmgr = 0; | 329 videodata->ime_threadmgr = 0; |
332 } | 330 } |
333 if (videodata->ime_com_initialized) | 331 if (videodata->ime_com_initialized) { |
334 { | |
335 CoUninitialize(); | 332 CoUninitialize(); |
336 videodata->ime_com_initialized = SDL_FALSE; | 333 videodata->ime_com_initialized = SDL_FALSE; |
337 } | 334 } |
338 videodata->ime_initialized = SDL_FALSE; | 335 videodata->ime_initialized = SDL_FALSE; |
339 } | 336 } |
352 static OSVERSIONINFOA osversion = {0}; | 349 static OSVERSIONINFOA osversion = {0}; |
353 if (videodata->ime_uiless) | 350 if (videodata->ime_uiless) |
354 return; | 351 return; |
355 | 352 |
356 videodata->ime_readingstring[0] = 0; | 353 videodata->ime_readingstring[0] = 0; |
357 if (!osversion.dwOSVersionInfoSize) | 354 if (!osversion.dwOSVersionInfoSize) { |
358 { | |
359 osversion.dwOSVersionInfoSize = sizeof(osversion); | 355 osversion.dwOSVersionInfoSize = sizeof(osversion); |
360 GetVersionExA(&osversion); | 356 GetVersionExA(&osversion); |
361 } | 357 } |
362 id = IME_GetId(videodata, 0); | 358 id = IME_GetId(videodata, 0); |
363 if (!id) | 359 if (!id) |
365 | 361 |
366 himc = ImmGetContext(hwnd); | 362 himc = ImmGetContext(hwnd); |
367 if (!himc) | 363 if (!himc) |
368 return; | 364 return; |
369 | 365 |
370 if (videodata->GetReadingString) | 366 if (videodata->GetReadingString) { |
371 { | |
372 len = videodata->GetReadingString(himc, 0, 0, &err, &vertical, &maxuilen); | 367 len = videodata->GetReadingString(himc, 0, 0, &err, &vertical, &maxuilen); |
373 if (len) | 368 if (len) { |
374 { | |
375 if (len > SDL_arraysize(buffer)) | 369 if (len > SDL_arraysize(buffer)) |
376 len = SDL_arraysize(buffer); | 370 len = SDL_arraysize(buffer); |
377 | 371 |
378 len = videodata->GetReadingString(himc, len, s, &err, &vertical, &maxuilen); | 372 len = videodata->GetReadingString(himc, len, s, &err, &vertical, &maxuilen); |
379 } | 373 } |
380 SDL_wcslcpy(videodata->ime_readingstring, s, len); | 374 SDL_wcslcpy(videodata->ime_readingstring, s, len); |
381 } | 375 } |
382 else | 376 else { |
383 { | |
384 LPINPUTCONTEXT2 lpimc = videodata->ImmLockIMC(himc); | 377 LPINPUTCONTEXT2 lpimc = videodata->ImmLockIMC(himc); |
385 LPBYTE p = 0; | 378 LPBYTE p = 0; |
386 s = 0; | 379 s = 0; |
387 switch (id) | 380 switch (id) |
388 { | 381 { |
432 len = *(DWORD *)(p + 1*4 + (16*2+2*4) + 5*4 + 16*2); | 425 len = *(DWORD *)(p + 1*4 + (16*2+2*4) + 5*4 + 16*2); |
433 s = (WCHAR *)(p + 1*4 + (16*2+2*4) + 5*4); | 426 s = (WCHAR *)(p + 1*4 + (16*2+2*4) + 5*4); |
434 break; | 427 break; |
435 } | 428 } |
436 if (s) | 429 if (s) |
437 { | |
438 SDL_wcslcpy(videodata->ime_readingstring, s, len + 1); | 430 SDL_wcslcpy(videodata->ime_readingstring, s, len + 1); |
439 } | 431 |
440 videodata->ImmUnlockIMCC(lpimc->hPrivate); | 432 videodata->ImmUnlockIMCC(lpimc->hPrivate); |
441 videodata->ImmUnlockIMC(himc); | 433 videodata->ImmUnlockIMC(himc); |
442 } | 434 } |
443 ImmReleaseContext(hwnd, himc); | 435 ImmReleaseContext(hwnd, himc); |
444 IME_SendEditingEvent(videodata); | 436 IME_SendEditingEvent(videodata); |
445 } | 437 } |
446 | 438 |
447 static void | 439 static void |
448 IME_InputLangChanged(SDL_VideoData *videodata) | 440 IME_InputLangChanged(SDL_VideoData *videodata) |
449 { | 441 { |
450 UINT uLang = PRIMLANG(); | 442 UINT lang = PRIMLANG(); |
451 HWND hwndime = 0; | 443 HWND hwndime = 0; |
452 IME_UpdateInputLocale(videodata); | 444 IME_UpdateInputLocale(videodata); |
453 IME_SetupAPI(videodata); | 445 IME_SetupAPI(videodata); |
454 if (uLang != PRIMLANG()) | 446 if (lang != PRIMLANG()) { |
455 { | |
456 IME_ClearComposition(videodata); | 447 IME_ClearComposition(videodata); |
457 } | 448 } |
458 hwndime = ImmGetDefaultIMEWnd(videodata->ime_hwnd_current); | 449 hwndime = ImmGetDefaultIMEWnd(videodata->ime_hwnd_current); |
459 if (hwndime) | 450 if (hwndime) { |
460 { | |
461 SendMessageA(hwndime, WM_IME_CONTROL, IMC_OPENSTATUSWINDOW, 0); | 451 SendMessageA(hwndime, WM_IME_CONTROL, IMC_OPENSTATUSWINDOW, 0); |
462 SendMessageA(hwndime, WM_IME_CONTROL, IMC_CLOSESTATUSWINDOW, 0); | 452 SendMessageA(hwndime, WM_IME_CONTROL, IMC_CLOSESTATUSWINDOW, 0); |
463 } | 453 } |
464 } | 454 } |
465 | 455 |
483 if (hklprev == hkl) | 473 if (hklprev == hkl) |
484 return dwRet[uIndex]; | 474 return dwRet[uIndex]; |
485 | 475 |
486 hklprev = hkl; | 476 hklprev = hkl; |
487 dwLang = ((DWORD)hkl & 0xffff); | 477 dwLang = ((DWORD)hkl & 0xffff); |
488 if (videodata->ime_uiless && LANG() == LANG_CHT) | 478 if (videodata->ime_uiless && LANG() == LANG_CHT) { |
489 { | |
490 dwRet[0] = IMEID_CHT_VER_VISTA; | 479 dwRet[0] = IMEID_CHT_VER_VISTA; |
491 dwRet[1] = 0; | 480 dwRet[1] = 0; |
492 return dwRet[0]; | 481 return dwRet[0]; |
493 } | 482 } |
494 if (hkl != CHT_HKL_NEW_PHONETIC | 483 if (hkl != CHT_HKL_NEW_PHONETIC |
495 && hkl != CHT_HKL_NEW_CHANG_JIE | 484 && hkl != CHT_HKL_NEW_CHANG_JIE |
496 && hkl != CHT_HKL_NEW_QUICK | 485 && hkl != CHT_HKL_NEW_QUICK |
497 && hkl != CHT_HKL_HK_CANTONESE | 486 && hkl != CHT_HKL_HK_CANTONESE |
498 && hkl != CHS_HKL) | 487 && hkl != CHS_HKL) { |
499 { | |
500 dwRet[0] = dwRet[1] = 0; | 488 dwRet[0] = dwRet[1] = 0; |
501 return dwRet[uIndex]; | 489 return dwRet[uIndex]; |
502 } | 490 } |
503 if (ImmGetIMEFileNameA(hkl, szTemp, sizeof(szTemp) - 1) <= 0) | 491 if (ImmGetIMEFileNameA(hkl, szTemp, sizeof(szTemp) - 1) <= 0) { |
504 { | |
505 dwRet[0] = dwRet[1] = 0; | 492 dwRet[0] = dwRet[1] = 0; |
506 return dwRet[uIndex]; | 493 return dwRet[uIndex]; |
507 } | 494 } |
508 if (!videodata->GetReadingString) | 495 if (!videodata->GetReadingString) { |
509 { | |
510 #define LCID_INVARIANT MAKELCID(MAKELANGID(LANG_ENGLISH, SUBLANG_ENGLISH_US), SORT_DEFAULT) | 496 #define LCID_INVARIANT MAKELCID(MAKELANGID(LANG_ENGLISH, SUBLANG_ENGLISH_US), SORT_DEFAULT) |
511 if (CompareStringA(LCID_INVARIANT, NORM_IGNORECASE, szTemp, -1, CHT_IMEFILENAME1, -1) != 2 | 497 if (CompareStringA(LCID_INVARIANT, NORM_IGNORECASE, szTemp, -1, CHT_IMEFILENAME1, -1) != 2 |
512 && CompareStringA(LCID_INVARIANT, NORM_IGNORECASE, szTemp, -1, CHT_IMEFILENAME2, -1) != 2 | 498 && CompareStringA(LCID_INVARIANT, NORM_IGNORECASE, szTemp, -1, CHT_IMEFILENAME2, -1) != 2 |
513 && CompareStringA(LCID_INVARIANT, NORM_IGNORECASE, szTemp, -1, CHT_IMEFILENAME3, -1) != 2 | 499 && CompareStringA(LCID_INVARIANT, NORM_IGNORECASE, szTemp, -1, CHT_IMEFILENAME3, -1) != 2 |
514 && CompareStringA(LCID_INVARIANT, NORM_IGNORECASE, szTemp, -1, CHS_IMEFILENAME1, -1) != 2 | 500 && CompareStringA(LCID_INVARIANT, NORM_IGNORECASE, szTemp, -1, CHS_IMEFILENAME1, -1) != 2 |
515 && CompareStringA(LCID_INVARIANT, NORM_IGNORECASE, szTemp, -1, CHS_IMEFILENAME2, -1) != 2 | 501 && CompareStringA(LCID_INVARIANT, NORM_IGNORECASE, szTemp, -1, CHS_IMEFILENAME2, -1) != 2) { |
516 ) | |
517 { | |
518 dwRet[0] = dwRet[1] = 0; | 502 dwRet[0] = dwRet[1] = 0; |
519 return dwRet[uIndex]; | 503 return dwRet[uIndex]; |
520 } | 504 } |
521 #undef LCID_INVARIANT | 505 #undef LCID_INVARIANT |
522 dwVerSize = GetFileVersionInfoSizeA(szTemp, &dwVerHandle); | 506 dwVerSize = GetFileVersionInfoSizeA(szTemp, &dwVerHandle); |
523 if (dwVerSize) | 507 if (dwVerSize) { |
524 { | |
525 lpVerBuffer = SDL_malloc(dwVerSize); | 508 lpVerBuffer = SDL_malloc(dwVerSize); |
526 if (lpVerBuffer) | 509 if (lpVerBuffer) { |
527 { | 510 if (GetFileVersionInfoA(szTemp, dwVerHandle, dwVerSize, lpVerBuffer)) { |
528 if (GetFileVersionInfoA(szTemp, dwVerHandle, dwVerSize, lpVerBuffer)) | 511 if (VerQueryValueA(lpVerBuffer, "\\", &lpVerData, &cbVerData)) { |
529 { | |
530 if (VerQueryValueA(lpVerBuffer, "\\", &lpVerData, &cbVerData)) | |
531 { | |
532 #define pVerFixedInfo ((VS_FIXEDFILEINFO FAR*)lpVerData) | 512 #define pVerFixedInfo ((VS_FIXEDFILEINFO FAR*)lpVerData) |
533 DWORD dwVer = pVerFixedInfo->dwFileVersionMS; | 513 DWORD dwVer = pVerFixedInfo->dwFileVersionMS; |
534 dwVer = (dwVer & 0x00ff0000) << 8 | (dwVer & 0x000000ff) << 16; | 514 dwVer = (dwVer & 0x00ff0000) << 8 | (dwVer & 0x000000ff) << 16; |
535 if (videodata->GetReadingString || | 515 if (videodata->GetReadingString || |
536 dwLang == LANG_CHT && ( | 516 dwLang == LANG_CHT && ( |
543 dwVer == MAKEIMEVERSION(6, 0)) | 523 dwVer == MAKEIMEVERSION(6, 0)) |
544 || | 524 || |
545 dwLang == LANG_CHS && ( | 525 dwLang == LANG_CHS && ( |
546 dwVer == MAKEIMEVERSION(4, 1) || | 526 dwVer == MAKEIMEVERSION(4, 1) || |
547 dwVer == MAKEIMEVERSION(4, 2) || | 527 dwVer == MAKEIMEVERSION(4, 2) || |
548 dwVer == MAKEIMEVERSION(5, 3)) | 528 dwVer == MAKEIMEVERSION(5, 3))) { |
549 ) | |
550 { | |
551 dwRet[0] = dwVer | dwLang; | 529 dwRet[0] = dwVer | dwLang; |
552 dwRet[1] = pVerFixedInfo->dwFileVersionLS; | 530 dwRet[1] = pVerFixedInfo->dwFileVersionLS; |
553 SDL_free(lpVerBuffer); | 531 SDL_free(lpVerBuffer); |
554 return dwRet[0]; | 532 return dwRet[0]; |
555 } | 533 } |
586 videodata->GetReadingString = (UINT (WINAPI *)(HIMC, UINT, LPWSTR, PINT, BOOL*, PUINT)) | 564 videodata->GetReadingString = (UINT (WINAPI *)(HIMC, UINT, LPWSTR, PINT, BOOL*, PUINT)) |
587 GetProcAddress(hime, "GetReadingString"); | 565 GetProcAddress(hime, "GetReadingString"); |
588 videodata->ShowReadingWindow = (BOOL (WINAPI *)(HIMC, BOOL)) | 566 videodata->ShowReadingWindow = (BOOL (WINAPI *)(HIMC, BOOL)) |
589 GetProcAddress(hime, "ShowReadingWindow"); | 567 GetProcAddress(hime, "ShowReadingWindow"); |
590 | 568 |
591 if (videodata->ShowReadingWindow) | 569 if (videodata->ShowReadingWindow) { |
592 { | |
593 HIMC himc = ImmGetContext(videodata->ime_hwnd_current); | 570 HIMC himc = ImmGetContext(videodata->ime_hwnd_current); |
594 if (himc) | 571 if (himc) { |
595 { | |
596 videodata->ShowReadingWindow(himc, FALSE); | 572 videodata->ShowReadingWindow(himc, FALSE); |
597 ImmReleaseContext(videodata->ime_hwnd_current, himc); | 573 ImmReleaseContext(videodata->ime_hwnd_current, himc); |
598 } | 574 } |
599 } | 575 } |
600 } | 576 } |
613 } | 589 } |
614 | 590 |
615 static void | 591 static void |
616 IME_UpdateInputLocale(SDL_VideoData *videodata) | 592 IME_UpdateInputLocale(SDL_VideoData *videodata) |
617 { | 593 { |
618 static HKL hklPrevious = 0; | 594 static HKL hklprev = 0; |
619 videodata->ime_hkl = GetKeyboardLayout(0); | 595 videodata->ime_hkl = GetKeyboardLayout(0); |
620 if (hklPrevious == videodata->ime_hkl) | 596 if (hklprev == videodata->ime_hkl) |
621 return; | 597 return; |
622 | 598 |
623 hklPrevious = videodata->ime_hkl; | 599 hklprev = videodata->ime_hkl; |
624 } | 600 } |
625 | 601 |
626 static void | 602 static void |
627 IME_ClearComposition(SDL_VideoData *videodata) | 603 IME_ClearComposition(SDL_VideoData *videodata) |
628 { | 604 { |
650 } | 626 } |
651 | 627 |
652 static void | 628 static void |
653 IME_GetCompositionString(SDL_VideoData *videodata, HIMC himc, DWORD string) | 629 IME_GetCompositionString(SDL_VideoData *videodata, HIMC himc, DWORD string) |
654 { | 630 { |
655 LONG Length = ImmGetCompositionStringW(himc, string, videodata->ime_composition, sizeof(videodata->ime_composition)); | 631 LONG length = ImmGetCompositionStringW(himc, string, videodata->ime_composition, sizeof(videodata->ime_composition)); |
656 if (Length < 0) | 632 if (length < 0) |
657 Length = 0; | 633 length = 0; |
658 | 634 |
659 Length /= sizeof(videodata->ime_composition[0]); | 635 length /= sizeof(videodata->ime_composition[0]); |
660 videodata->ime_cursor = LOWORD(ImmGetCompositionStringW(himc, GCS_CURSORPOS, 0, 0)); | 636 videodata->ime_cursor = LOWORD(ImmGetCompositionStringW(himc, GCS_CURSORPOS, 0, 0)); |
661 if (videodata->ime_composition[videodata->ime_cursor] == 0x3000) | 637 if (videodata->ime_composition[videodata->ime_cursor] == 0x3000) { |
662 { | |
663 int i; | 638 int i; |
664 for (i = videodata->ime_cursor + 1; i < Length; ++i) | 639 for (i = videodata->ime_cursor + 1; i < length; ++i) |
665 videodata->ime_composition[i - 1] = videodata->ime_composition[i]; | 640 videodata->ime_composition[i - 1] = videodata->ime_composition[i]; |
666 | 641 |
667 --Length; | 642 --length; |
668 } | 643 } |
669 videodata->ime_composition[Length] = 0; | 644 videodata->ime_composition[length] = 0; |
670 } | 645 } |
671 | 646 |
672 static void | 647 static void |
673 IME_SendInputEvent(SDL_VideoData *videodata) | 648 IME_SendInputEvent(SDL_VideoData *videodata) |
674 { | 649 { |
684 | 659 |
685 static void | 660 static void |
686 IME_SendEditingEvent(SDL_VideoData *videodata) | 661 IME_SendEditingEvent(SDL_VideoData *videodata) |
687 { | 662 { |
688 char *s = 0; | 663 char *s = 0; |
689 WCHAR wBuffer[SDL_TEXTEDITINGEVENT_TEXT_SIZE]; | 664 WCHAR buffer[SDL_TEXTEDITINGEVENT_TEXT_SIZE]; |
690 wBuffer[0] = 0; | 665 buffer[0] = 0; |
691 if (videodata->ime_readingstring[0]) | 666 if (videodata->ime_readingstring[0]) { |
692 { | |
693 size_t len = SDL_min(SDL_wcslen(videodata->ime_composition), (size_t)videodata->ime_cursor); | 667 size_t len = SDL_min(SDL_wcslen(videodata->ime_composition), (size_t)videodata->ime_cursor); |
694 SDL_wcslcpy(wBuffer, videodata->ime_composition, len + 1); | 668 SDL_wcslcpy(buffer, videodata->ime_composition, len + 1); |
695 SDL_wcslcat(wBuffer, videodata->ime_readingstring, sizeof(wBuffer)); | 669 SDL_wcslcat(buffer, videodata->ime_readingstring, sizeof(buffer)); |
696 SDL_wcslcat(wBuffer, &videodata->ime_composition[len], sizeof(wBuffer) - len); | 670 SDL_wcslcat(buffer, &videodata->ime_composition[len], sizeof(buffer) - len); |
697 } | 671 } |
698 else | 672 else { |
699 { | 673 SDL_wcslcpy(buffer, videodata->ime_composition, sizeof(videodata->ime_composition)); |
700 SDL_wcslcpy(wBuffer, videodata->ime_composition, sizeof(videodata->ime_composition)); | 674 } |
701 } | 675 s = WIN_StringToUTF8(buffer); |
702 s = WIN_StringToUTF8(wBuffer); | |
703 SDL_SendEditingText(s, videodata->ime_cursor + SDL_wcslen(videodata->ime_readingstring), 0); | 676 SDL_SendEditingText(s, videodata->ime_cursor + SDL_wcslen(videodata->ime_readingstring), 0); |
704 SDL_free(s); | 677 SDL_free(s); |
705 } | 678 } |
706 | 679 |
707 SDL_bool | 680 SDL_bool |
724 trap = SDL_TRUE; | 697 trap = SDL_TRUE; |
725 break; | 698 break; |
726 case WM_IME_COMPOSITION: | 699 case WM_IME_COMPOSITION: |
727 trap = SDL_TRUE; | 700 trap = SDL_TRUE; |
728 himc = ImmGetContext(hwnd); | 701 himc = ImmGetContext(hwnd); |
729 if (*lParam & GCS_RESULTSTR) | 702 if (*lParam & GCS_RESULTSTR) { |
730 { | |
731 IME_GetCompositionString(videodata, himc, GCS_RESULTSTR); | 703 IME_GetCompositionString(videodata, himc, GCS_RESULTSTR); |
732 IME_SendInputEvent(videodata); | 704 IME_SendInputEvent(videodata); |
733 } | 705 } |
734 if (*lParam & GCS_COMPSTR) | 706 if (*lParam & GCS_COMPSTR) { |
735 { | |
736 if (!videodata->ime_uiless) | 707 if (!videodata->ime_uiless) |
737 videodata->ime_readingstring[0] = 0; | 708 videodata->ime_readingstring[0] = 0; |
738 | 709 |
739 IME_GetCompositionString(videodata, himc, GCS_COMPSTR); | 710 IME_GetCompositionString(videodata, himc, GCS_COMPSTR); |
740 IME_SendEditingEvent(videodata); | 711 IME_SendEditingEvent(videodata); |
825 if (SDL_IsEqualIID(riid, &IID_IUnknown)) | 796 if (SDL_IsEqualIID(riid, &IID_IUnknown)) |
826 *ppv = (IUnknown *)sink; | 797 *ppv = (IUnknown *)sink; |
827 else if (SDL_IsEqualIID(riid, &IID_ITfUIElementSink)) | 798 else if (SDL_IsEqualIID(riid, &IID_ITfUIElementSink)) |
828 *ppv = (ITfUIElementSink *)sink; | 799 *ppv = (ITfUIElementSink *)sink; |
829 | 800 |
830 if (*ppv) | 801 if (*ppv) { |
831 { | |
832 TSFSink_AddRef(sink); | 802 TSFSink_AddRef(sink); |
833 return S_OK; | 803 return S_OK; |
834 } | 804 } |
835 return E_NOINTERFACE; | 805 return E_NOINTERFACE; |
836 } | 806 } |
839 { | 809 { |
840 ITfUIElementMgr *puiem = 0; | 810 ITfUIElementMgr *puiem = 0; |
841 ITfUIElement *pelem = 0; | 811 ITfUIElement *pelem = 0; |
842 ITfThreadMgrEx *threadmgrex = videodata->ime_threadmgrex; | 812 ITfThreadMgrEx *threadmgrex = videodata->ime_threadmgrex; |
843 | 813 |
844 if (SUCCEEDED(threadmgrex->lpVtbl->QueryInterface(threadmgrex, &IID_ITfUIElementMgr, (LPVOID *)&puiem))) | 814 if (SUCCEEDED(threadmgrex->lpVtbl->QueryInterface(threadmgrex, &IID_ITfUIElementMgr, (LPVOID *)&puiem))) { |
845 { | |
846 puiem->lpVtbl->GetUIElement(puiem, dwUIElementId, &pelem); | 815 puiem->lpVtbl->GetUIElement(puiem, dwUIElementId, &pelem); |
847 puiem->lpVtbl->Release(puiem); | 816 puiem->lpVtbl->Release(puiem); |
848 } | 817 } |
849 return pelem; | 818 return pelem; |
850 } | 819 } |
851 | 820 |
852 STDMETHODIMP UIElementSink_BeginUIElement(TSFSink *sink, DWORD dwUIElementId, BOOL *pbShow) | 821 STDMETHODIMP UIElementSink_BeginUIElement(TSFSink *sink, DWORD dwUIElementId, BOOL *pbShow) |
853 { | 822 { |
854 ITfUIElement *pElement = UILess_GetUIElement((SDL_VideoData *)sink->data, dwUIElementId); | 823 ITfUIElement *element = UILess_GetUIElement((SDL_VideoData *)sink->data, dwUIElementId); |
855 ITfReadingInformationUIElement *preading = 0; | 824 ITfReadingInformationUIElement *preading = 0; |
856 ITfCandidateListUIElement *pcandidates = 0; | |
857 SDL_VideoData *videodata = (SDL_VideoData *)sink->data; | 825 SDL_VideoData *videodata = (SDL_VideoData *)sink->data; |
858 if (!pElement) | 826 if (!element) |
859 return E_INVALIDARG; | 827 return E_INVALIDARG; |
860 | 828 |
861 *pbShow = FALSE; | 829 *pbShow = FALSE; |
862 if (SUCCEEDED(pElement->lpVtbl->QueryInterface(pElement, &IID_ITfReadingInformationUIElement, (LPVOID *)&preading))) | 830 if (SUCCEEDED(element->lpVtbl->QueryInterface(element, &IID_ITfReadingInformationUIElement, (LPVOID *)&preading))) { |
863 { | |
864 BSTR bstr; | 831 BSTR bstr; |
865 if (SUCCEEDED(preading->lpVtbl->GetString(preading, &bstr)) && bstr) | 832 if (SUCCEEDED(preading->lpVtbl->GetString(preading, &bstr)) && bstr) { |
866 { | |
867 WCHAR *s = (WCHAR *)bstr; | 833 WCHAR *s = (WCHAR *)bstr; |
868 SysFreeString(bstr); | 834 SysFreeString(bstr); |
869 } | 835 } |
870 preading->lpVtbl->Release(preading); | 836 preading->lpVtbl->Release(preading); |
871 } | 837 } |
872 else if (SUCCEEDED(pElement->lpVtbl->QueryInterface(pElement, &IID_ITfCandidateListUIElement, (PVOID *)&pcandidates))) | |
873 { | |
874 pcandidates->lpVtbl->Release(pcandidates); | |
875 } | |
876 return S_OK; | 838 return S_OK; |
877 } | 839 } |
878 | 840 |
879 STDMETHODIMP UIElementSink_UpdateUIElement(TSFSink *sink, DWORD dwUIElementId) | 841 STDMETHODIMP UIElementSink_UpdateUIElement(TSFSink *sink, DWORD dwUIElementId) |
880 { | 842 { |
881 ITfUIElement *pElement = UILess_GetUIElement((SDL_VideoData *)sink->data, dwUIElementId); | 843 ITfUIElement *element = UILess_GetUIElement((SDL_VideoData *)sink->data, dwUIElementId); |
882 ITfReadingInformationUIElement *preading = 0; | 844 ITfReadingInformationUIElement *preading = 0; |
883 ITfCandidateListUIElement *pcandidates = 0; | |
884 SDL_VideoData *videodata = (SDL_VideoData *)sink->data; | 845 SDL_VideoData *videodata = (SDL_VideoData *)sink->data; |
885 if (!pElement) | 846 if (!element) |
886 return E_INVALIDARG; | 847 return E_INVALIDARG; |
887 | 848 |
888 if (SUCCEEDED(pElement->lpVtbl->QueryInterface(pElement, &IID_ITfReadingInformationUIElement, (LPVOID *)&preading))) | 849 if (SUCCEEDED(element->lpVtbl->QueryInterface(element, &IID_ITfReadingInformationUIElement, (LPVOID *)&preading))) { |
889 { | |
890 BSTR bstr; | 850 BSTR bstr; |
891 if (SUCCEEDED(preading->lpVtbl->GetString(preading, &bstr)) && bstr) | 851 if (SUCCEEDED(preading->lpVtbl->GetString(preading, &bstr)) && bstr) { |
892 { | |
893 WCHAR *s = (WCHAR *)bstr; | 852 WCHAR *s = (WCHAR *)bstr; |
894 SDL_wcslcpy(videodata->ime_readingstring, s, sizeof(videodata->ime_readingstring)); | 853 SDL_wcslcpy(videodata->ime_readingstring, s, sizeof(videodata->ime_readingstring)); |
895 IME_SendEditingEvent(videodata); | 854 IME_SendEditingEvent(videodata); |
896 SysFreeString(bstr); | 855 SysFreeString(bstr); |
897 } | 856 } |
898 preading->lpVtbl->Release(preading); | 857 preading->lpVtbl->Release(preading); |
899 } | 858 } |
900 else if (SUCCEEDED(pElement->lpVtbl->QueryInterface(pElement, &IID_ITfCandidateListUIElement, (PVOID *)&pcandidates))) | |
901 { | |
902 pcandidates->lpVtbl->Release(pcandidates); | |
903 } | |
904 return S_OK; | 859 return S_OK; |
905 } | 860 } |
906 | 861 |
907 STDMETHODIMP UIElementSink_EndUIElement(TSFSink *sink, DWORD dwUIElementId) | 862 STDMETHODIMP UIElementSink_EndUIElement(TSFSink *sink, DWORD dwUIElementId) |
908 { | 863 { |
909 ITfUIElement *pElement = UILess_GetUIElement((SDL_VideoData *)sink->data, dwUIElementId); | 864 ITfUIElement *element = UILess_GetUIElement((SDL_VideoData *)sink->data, dwUIElementId); |
910 ITfReadingInformationUIElement *preading = 0; | 865 ITfReadingInformationUIElement *preading = 0; |
911 ITfCandidateListUIElement *pcandidates = 0; | |
912 SDL_VideoData *videodata = (SDL_VideoData *)sink->data; | 866 SDL_VideoData *videodata = (SDL_VideoData *)sink->data; |
913 if (!pElement) | 867 if (!element) |
914 return E_INVALIDARG; | 868 return E_INVALIDARG; |
915 | 869 |
916 if (SUCCEEDED(pElement->lpVtbl->QueryInterface(pElement, &IID_ITfReadingInformationUIElement, (LPVOID *)&preading))) | 870 if (SUCCEEDED(element->lpVtbl->QueryInterface(element, &IID_ITfReadingInformationUIElement, (LPVOID *)&preading))) { |
917 { | |
918 videodata->ime_readingstring[0] = 0; | 871 videodata->ime_readingstring[0] = 0; |
919 IME_SendEditingEvent(videodata); | 872 IME_SendEditingEvent(videodata); |
920 preading->lpVtbl->Release(preading); | 873 preading->lpVtbl->Release(preading); |
921 } | |
922 else if (SUCCEEDED(pElement->lpVtbl->QueryInterface(pElement, &IID_ITfCandidateListUIElement, (PVOID *)&pcandidates))) | |
923 { | |
924 pcandidates->lpVtbl->Release(pcandidates); | |
925 } | 874 } |
926 return S_OK; | 875 return S_OK; |
927 } | 876 } |
928 | 877 |
929 STDMETHODIMP IPPASink_QueryInterface(TSFSink *sink, REFIID riid, PVOID *ppv) | 878 STDMETHODIMP IPPASink_QueryInterface(TSFSink *sink, REFIID riid, PVOID *ppv) |
935 if (SDL_IsEqualIID(riid, &IID_IUnknown)) | 884 if (SDL_IsEqualIID(riid, &IID_IUnknown)) |
936 *ppv = (IUnknown *)sink; | 885 *ppv = (IUnknown *)sink; |
937 else if (SDL_IsEqualIID(riid, &IID_ITfInputProcessorProfileActivationSink)) | 886 else if (SDL_IsEqualIID(riid, &IID_ITfInputProcessorProfileActivationSink)) |
938 *ppv = (ITfInputProcessorProfileActivationSink *)sink; | 887 *ppv = (ITfInputProcessorProfileActivationSink *)sink; |
939 | 888 |
940 if (*ppv) | 889 if (*ppv) { |
941 { | |
942 TSFSink_AddRef(sink); | 890 TSFSink_AddRef(sink); |
943 return S_OK; | 891 return S_OK; |
944 } | 892 } |
945 return E_NOINTERFACE; | 893 return E_NOINTERFACE; |
946 } | 894 } |
974 { | 922 { |
975 ITfSource *source = 0; | 923 ITfSource *source = 0; |
976 if (!videodata->ime_threadmgrex || videodata->ime_uielemsinkcookie != TF_INVALID_COOKIE) | 924 if (!videodata->ime_threadmgrex || videodata->ime_uielemsinkcookie != TF_INVALID_COOKIE) |
977 return; | 925 return; |
978 | 926 |
979 if (SUCCEEDED(videodata->ime_threadmgrex->lpVtbl->QueryInterface(videodata->ime_threadmgrex, &IID_ITfSource, (LPVOID *)&source))) | 927 if (SUCCEEDED(videodata->ime_threadmgrex->lpVtbl->QueryInterface(videodata->ime_threadmgrex, &IID_ITfSource, (LPVOID *)&source))) { |
980 { | |
981 source->lpVtbl->AdviseSink(source, &IID_ITfUIElementSink, (IUnknown *)videodata->ime_uielemsink, &videodata->ime_uielemsinkcookie); | 928 source->lpVtbl->AdviseSink(source, &IID_ITfUIElementSink, (IUnknown *)videodata->ime_uielemsink, &videodata->ime_uielemsinkcookie); |
982 source->lpVtbl->Release(source); | 929 source->lpVtbl->Release(source); |
983 } | 930 } |
984 } | 931 } |
985 | 932 |
988 { | 935 { |
989 ITfSource *source = 0; | 936 ITfSource *source = 0; |
990 if (!videodata->ime_threadmgrex || videodata->ime_uielemsinkcookie == TF_INVALID_COOKIE) | 937 if (!videodata->ime_threadmgrex || videodata->ime_uielemsinkcookie == TF_INVALID_COOKIE) |
991 return; | 938 return; |
992 | 939 |
993 if (SUCCEEDED(videodata->ime_threadmgrex->lpVtbl->QueryInterface(videodata->ime_threadmgrex, &IID_ITfSource, (LPVOID *)&source))) | 940 if (SUCCEEDED(videodata->ime_threadmgrex->lpVtbl->QueryInterface(videodata->ime_threadmgrex, &IID_ITfSource, (LPVOID *)&source))) { |
994 { | |
995 source->lpVtbl->UnadviseSink(source, videodata->ime_uielemsinkcookie); | 941 source->lpVtbl->UnadviseSink(source, videodata->ime_uielemsinkcookie); |
996 videodata->ime_uielemsinkcookie = TF_INVALID_COOKIE; | 942 videodata->ime_uielemsinkcookie = TF_INVALID_COOKIE; |
997 source->lpVtbl->Release(source); | 943 source->lpVtbl->Release(source); |
998 } | 944 } |
999 } | 945 } |
1019 | 965 |
1020 videodata->ime_ippasink->lpVtbl = vtIPPASink; | 966 videodata->ime_ippasink->lpVtbl = vtIPPASink; |
1021 videodata->ime_ippasink->refcount = 1; | 967 videodata->ime_ippasink->refcount = 1; |
1022 videodata->ime_ippasink->data = videodata; | 968 videodata->ime_ippasink->data = videodata; |
1023 | 969 |
1024 if (SUCCEEDED(videodata->ime_threadmgrex->lpVtbl->QueryInterface(videodata->ime_threadmgrex, &IID_ITfSource, (LPVOID *)&source))) | 970 if (SUCCEEDED(videodata->ime_threadmgrex->lpVtbl->QueryInterface(videodata->ime_threadmgrex, &IID_ITfSource, (LPVOID *)&source))) { |
1025 { | 971 if (SUCCEEDED(source->lpVtbl->AdviseSink(source, &IID_ITfUIElementSink, (IUnknown *)videodata->ime_uielemsink, &videodata->ime_uielemsinkcookie))) { |
1026 if (SUCCEEDED(source->lpVtbl->AdviseSink(source, &IID_ITfUIElementSink, (IUnknown *)videodata->ime_uielemsink, &videodata->ime_uielemsinkcookie))) | 972 if (SUCCEEDED(source->lpVtbl->AdviseSink(source, &IID_ITfInputProcessorProfileActivationSink, (IUnknown *)videodata->ime_ippasink, &videodata->ime_alpnsinkcookie))) { |
1027 { | |
1028 if (SUCCEEDED(source->lpVtbl->AdviseSink(source, &IID_ITfInputProcessorProfileActivationSink, (IUnknown *)videodata->ime_ippasink, &videodata->ime_alpnsinkcookie))) | |
1029 { | |
1030 result = SDL_TRUE; | 973 result = SDL_TRUE; |
1031 } | 974 } |
1032 } | 975 } |
1033 source->lpVtbl->Release(source); | 976 source->lpVtbl->Release(source); |
1034 } | 977 } |
1044 } | 987 } |
1045 | 988 |
1046 static void | 989 static void |
1047 UILess_ReleaseSinks(SDL_VideoData *videodata) | 990 UILess_ReleaseSinks(SDL_VideoData *videodata) |
1048 { | 991 { |
1049 ITfSource *Source = 0; | 992 ITfSource *source = 0; |
1050 if (videodata->ime_threadmgrex && SUCCEEDED(videodata->ime_threadmgrex->lpVtbl->QueryInterface(videodata->ime_threadmgrex, &IID_ITfSource, &Source))) | 993 if (videodata->ime_threadmgrex && SUCCEEDED(videodata->ime_threadmgrex->lpVtbl->QueryInterface(videodata->ime_threadmgrex, &IID_ITfSource, &source))) { |
1051 { | 994 source->lpVtbl->UnadviseSink(source, videodata->ime_uielemsinkcookie); |
1052 Source->lpVtbl->UnadviseSink(Source, videodata->ime_uielemsinkcookie); | 995 source->lpVtbl->UnadviseSink(source, videodata->ime_alpnsinkcookie); |
1053 Source->lpVtbl->UnadviseSink(Source, videodata->ime_alpnsinkcookie); | 996 SAFE_RELEASE(source); |
1054 SAFE_RELEASE(Source); | |
1055 videodata->ime_threadmgrex->lpVtbl->Deactivate(videodata->ime_threadmgrex); | 997 videodata->ime_threadmgrex->lpVtbl->Deactivate(videodata->ime_threadmgrex); |
1056 SAFE_RELEASE(videodata->ime_threadmgrex); | 998 SAFE_RELEASE(videodata->ime_threadmgrex); |
1057 TSFSink_Release(videodata->ime_uielemsink); | 999 TSFSink_Release(videodata->ime_uielemsink); |
1058 videodata->ime_uielemsink = 0; | 1000 videodata->ime_uielemsink = 0; |
1059 TSFSink_Release(videodata->ime_ippasink); | 1001 TSFSink_Release(videodata->ime_ippasink); |