cleanup IME_GetCandidateList / UILess_GetCandidateList - move IME_ShowCandidateList, ImmGetContext and ImmReleaseContext to this function - set ime_candpgsize to MAX_CANDLIST if dwPageSize is zero - comment out deselection of ime_candsel in case of korean language for the moment (LANG_CHT does not work anyway)
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102
diff --git a/src/video/windows/SDL_windowskeyboard.c b/src/video/windows/SDL_windowskeyboard.c
index c68fe10..bdf431f 100644
--- a/src/video/windows/SDL_windowskeyboard.c
+++ b/src/video/windows/SDL_windowskeyboard.c
@@ -349,6 +349,7 @@ DEFINE_GUID(IID_ITfThreadMgrEx, 0x3E90ADE3,0x7594
#define SUBLANG() SUBLANGID(LANG())
static void IME_UpdateInputLocale(SDL_VideoData *videodata);
+static void IME_ShowCandidateList(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);
@@ -812,15 +813,23 @@ IME_AddCandidate(SDL_VideoData *videodata, UINT i, LPCWSTR candidate)
}
static void
-IME_GetCandidateList(HIMC himc, SDL_VideoData *videodata)
+IME_GetCandidateList(HWND hwnd, SDL_VideoData *videodata)
{
- LPCANDIDATELIST cand_list = 0;
- DWORD size = ImmGetCandidateListW(himc, 0, 0, 0);
- if (size) {
+ HIMC himc;
+ DWORD size;
+ LPCANDIDATELIST cand_list;
+
+ IME_ShowCandidateList(videodata);
+
+ himc = ImmGetContext(hwnd);
+ if (!himc)
+ return;
+ size = ImmGetCandidateListW(himc, 0, 0, 0);
+ if (size != 0) {
cand_list = (LPCANDIDATELIST)SDL_malloc(size);
- if (cand_list) {
+ if (cand_list != NULL) {
size = ImmGetCandidateListW(himc, 0, cand_list, size);
- if (size) {
+ if (size != 0) {
UINT i, j;
UINT page_start = 0;
videodata->ime_candsel = cand_list->dwSelection;
@@ -845,25 +854,23 @@ IME_GetCandidateList(HIMC himc, SDL_VideoData *videodata)
}
videodata->ime_candpgsize = i - page_start;
} else {
- videodata->ime_candpgsize = SDL_min(cand_list->dwPageSize, MAX_CANDLIST);
- if (videodata->ime_candpgsize > 0) {
- page_start = (cand_list->dwSelection / videodata->ime_candpgsize) * videodata->ime_candpgsize;
- } else {
- page_start = 0;
- }
+ videodata->ime_candpgsize = SDL_min(cand_list->dwPageSize == 0 ? MAX_CANDLIST : 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));
- for (i = page_start, j = 0; (DWORD)i < cand_list->dwCount && j < (int)videodata->ime_candpgsize; i++, j++) {
+ for (i = page_start, j = 0; (DWORD)i < cand_list->dwCount && j < videodata->ime_candpgsize; i++, j++) {
LPCWSTR candidate = (LPCWSTR)((DWORD_PTR)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;
+ // TODO: why was this necessary? check ime_candvertical instead? PRIMLANG() never equals LANG_CHT !
+ //if (PRIMLANG() == LANG_KOREAN || (PRIMLANG() == LANG_CHT && !IME_GetId(videodata, 0)))
+ // videodata->ime_candsel = -1;
}
SDL_free(cand_list);
}
}
+ ImmReleaseContext(hwnd, himc);
}
static void
@@ -938,13 +945,7 @@ IME_HandleMessage(HWND hwnd, UINT msg, WPARAM wParam, LPARAM *lParam, SDL_VideoD
break;
trap = SDL_TRUE;
- IME_ShowCandidateList(videodata);
- himc = ImmGetContext(hwnd);
- if (!himc)
- break;
-
- IME_GetCandidateList(himc, videodata);
- ImmReleaseContext(hwnd, himc);
+ IME_GetCandidateList(hwnd, videodata);
break;
case IMN_CLOSECANDIDATE:
trap = SDL_TRUE;
@@ -1042,8 +1043,9 @@ UILess_GetCandidateList(SDL_VideoData *videodata, ITfCandidateListUIElement *pca
}
}
}
- if (PRIMLANG() == LANG_KOREAN)
- videodata->ime_candsel = -1;
+ // TODO: why was this necessary? check ime_candvertical instead?
+ //if (PRIMLANG() == LANG_KOREAN)
+ // videodata->ime_candsel = -1;
}
STDMETHODIMP_(ULONG) TSFSink_AddRef(TSFSink *sink)