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)
This commit is contained in:
pionere 2022-01-18 17:49:33 +01:00 committed by Ryan C. Gordon
parent ec8e3104c8
commit 6f404d0f04

View file

@ -349,6 +349,7 @@ DEFINE_GUID(IID_ITfThreadMgrEx, 0x3E90ADE3,0x7594
#define SUBLANG() SUBLANGID(LANG()) #define SUBLANG() SUBLANGID(LANG())
static void IME_UpdateInputLocale(SDL_VideoData *videodata); static void IME_UpdateInputLocale(SDL_VideoData *videodata);
static void IME_ShowCandidateList(SDL_VideoData *videodata);
static void IME_ClearComposition(SDL_VideoData *videodata); static void IME_ClearComposition(SDL_VideoData *videodata);
static void IME_SetWindow(SDL_VideoData* videodata, HWND hwnd); static void IME_SetWindow(SDL_VideoData* videodata, HWND hwnd);
static void IME_SetupAPI(SDL_VideoData *videodata); static void IME_SetupAPI(SDL_VideoData *videodata);
@ -812,15 +813,23 @@ IME_AddCandidate(SDL_VideoData *videodata, UINT i, LPCWSTR candidate)
} }
static void static void
IME_GetCandidateList(HIMC himc, SDL_VideoData *videodata) IME_GetCandidateList(HWND hwnd, SDL_VideoData *videodata)
{ {
LPCANDIDATELIST cand_list = 0; HIMC himc;
DWORD size = ImmGetCandidateListW(himc, 0, 0, 0); DWORD size;
if (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); cand_list = (LPCANDIDATELIST)SDL_malloc(size);
if (cand_list) { if (cand_list != NULL) {
size = ImmGetCandidateListW(himc, 0, cand_list, size); size = ImmGetCandidateListW(himc, 0, cand_list, size);
if (size) { if (size != 0) {
UINT i, j; UINT i, j;
UINT page_start = 0; UINT page_start = 0;
videodata->ime_candsel = cand_list->dwSelection; videodata->ime_candsel = cand_list->dwSelection;
@ -845,25 +854,23 @@ IME_GetCandidateList(HIMC himc, SDL_VideoData *videodata)
} }
videodata->ime_candpgsize = i - page_start; videodata->ime_candpgsize = i - page_start;
} else { } else {
videodata->ime_candpgsize = SDL_min(cand_list->dwPageSize, MAX_CANDLIST); videodata->ime_candpgsize = SDL_min(cand_list->dwPageSize == 0 ? MAX_CANDLIST : cand_list->dwPageSize, MAX_CANDLIST);
if (videodata->ime_candpgsize > 0) {
page_start = (cand_list->dwSelection / videodata->ime_candpgsize) * videodata->ime_candpgsize; page_start = (cand_list->dwSelection / videodata->ime_candpgsize) * videodata->ime_candpgsize;
} else {
page_start = 0;
}
} }
SDL_memset(&videodata->ime_candidates, 0, sizeof(videodata->ime_candidates)); 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]); LPCWSTR candidate = (LPCWSTR)((DWORD_PTR)cand_list + cand_list->dwOffset[i]);
IME_AddCandidate(videodata, j, candidate); IME_AddCandidate(videodata, j, candidate);
} }
if (PRIMLANG() == LANG_KOREAN || (PRIMLANG() == LANG_CHT && !IME_GetId(videodata, 0))) // TODO: why was this necessary? check ime_candvertical instead? PRIMLANG() never equals LANG_CHT !
videodata->ime_candsel = -1; //if (PRIMLANG() == LANG_KOREAN || (PRIMLANG() == LANG_CHT && !IME_GetId(videodata, 0)))
// videodata->ime_candsel = -1;
} }
SDL_free(cand_list); SDL_free(cand_list);
} }
} }
ImmReleaseContext(hwnd, himc);
} }
static void static void
@ -938,13 +945,7 @@ IME_HandleMessage(HWND hwnd, UINT msg, WPARAM wParam, LPARAM *lParam, SDL_VideoD
break; break;
trap = SDL_TRUE; trap = SDL_TRUE;
IME_ShowCandidateList(videodata); IME_GetCandidateList(hwnd, videodata);
himc = ImmGetContext(hwnd);
if (!himc)
break;
IME_GetCandidateList(himc, videodata);
ImmReleaseContext(hwnd, himc);
break; break;
case IMN_CLOSECANDIDATE: case IMN_CLOSECANDIDATE:
trap = SDL_TRUE; trap = SDL_TRUE;
@ -1042,8 +1043,9 @@ UILess_GetCandidateList(SDL_VideoData *videodata, ITfCandidateListUIElement *pca
} }
} }
} }
if (PRIMLANG() == LANG_KOREAN) // TODO: why was this necessary? check ime_candvertical instead?
videodata->ime_candsel = -1; //if (PRIMLANG() == LANG_KOREAN)
// videodata->ime_candsel = -1;
} }
STDMETHODIMP_(ULONG) TSFSink_AddRef(TSFSink *sink) STDMETHODIMP_(ULONG) TSFSink_AddRef(TSFSink *sink)