Win32: Cosmetic changes

* Remove a needless local variable
* Shorten long lines
This commit is contained in:
Takuro Ashie 2022-04-15 14:33:57 +09:00 committed by Daijiro Fukuda
parent 4fd32183f8
commit 3e99fcc865

View File

@ -546,35 +546,36 @@ static void _win32ChangeCursorPosition(HIMC hIMC, _GLFWwindow* window)
static GLFWbool getImmPreedit(_GLFWwindow* window) static GLFWbool getImmPreedit(_GLFWwindow* window)
{ {
HWND hWnd = window->win32.handle; HIMC hIMC = ImmGetContext(window->win32.handle);
HIMC hIMC = ImmGetContext(hWnd);
// get preedit data sizes // get preedit data sizes
LONG preeditTextLength = ImmGetCompositionStringW(hIMC, GCS_COMPSTR, NULL, 0); LONG preeditBytes = ImmGetCompositionStringW(hIMC, GCS_COMPSTR, NULL, 0);
LONG attrLength = ImmGetCompositionStringW(hIMC, GCS_COMPATTR, NULL, 0); LONG attrBytes = ImmGetCompositionStringW(hIMC, GCS_COMPATTR, NULL, 0);
LONG clauseLength = ImmGetCompositionStringW(hIMC, GCS_COMPCLAUSE, NULL, 0); LONG clauseBytes = ImmGetCompositionStringW(hIMC, GCS_COMPCLAUSE, NULL, 0);
if (preeditTextLength > 0) if (preeditBytes > 0)
{ {
int i; int i;
int ctext = window->ctext; int ctext = window->ctext;
int cblocks = window->cblocks; int cblocks = window->cblocks;
int focusedBlock = 0; int focusedBlock = 0;
int length = preeditTextLength / sizeof(WCHAR); int length = preeditBytes / sizeof(WCHAR);
LPWSTR buffer = (LPWSTR) _glfw_calloc(preeditTextLength, 1); LPWSTR buffer = (LPWSTR) _glfw_calloc(preeditBytes, 1);
LPSTR attributes = (LPSTR) _glfw_calloc(attrLength, 1); LPSTR attributes = (LPSTR) _glfw_calloc(attrBytes, 1);
DWORD *clauses = (DWORD*) _glfw_calloc(clauseLength, 1); DWORD *clauses = (DWORD*) _glfw_calloc(clauseBytes, 1);
// get preedit data // get preedit data
ImmGetCompositionStringW(hIMC, GCS_COMPSTR, buffer, preeditTextLength); ImmGetCompositionStringW(hIMC, GCS_COMPSTR, buffer, preeditBytes);
ImmGetCompositionStringW(hIMC, GCS_COMPATTR, attributes, attrLength); ImmGetCompositionStringW(hIMC, GCS_COMPATTR, attributes, attrBytes);
ImmGetCompositionStringW(hIMC, GCS_COMPCLAUSE, clauses, clauseLength); ImmGetCompositionStringW(hIMC, GCS_COMPCLAUSE, clauses, clauseBytes);
// store preedit text // store preedit text
while (ctext < length + 1) while (ctext < length + 1)
ctext = (ctext == 0) ? 1 : ctext * 2; ctext = (ctext == 0) ? 1 : ctext * 2;
if (ctext != window->ctext) if (ctext != window->ctext)
{ {
unsigned int* preeditText = _glfw_realloc(window->preeditText, sizeof(unsigned int) * ctext); size_t bufsize = sizeof(unsigned int) * ctext;
unsigned int* preeditText = _glfw_realloc(window->preeditText,
bufsize);
if (preeditText == NULL) if (preeditText == NULL)
{ {
@ -592,7 +593,7 @@ static GLFWbool getImmPreedit(_GLFWwindow* window)
window->preeditText[i] = buffer[i]; window->preeditText[i] = buffer[i];
// store blocks // store blocks
window->nblocks = clauseLength / sizeof(DWORD) - 1; window->nblocks = clauseBytes / sizeof(DWORD) - 1;
// last element of clauses is a block count, but // last element of clauses is a block count, but
// text length is convenient. // text length is convenient.
clauses[window->nblocks] = length; clauses[window->nblocks] = length;
@ -600,7 +601,9 @@ static GLFWbool getImmPreedit(_GLFWwindow* window)
cblocks = (cblocks == 0) ? 1 : cblocks * 2; cblocks = (cblocks == 0) ? 1 : cblocks * 2;
if (cblocks != window->cblocks) if (cblocks != window->cblocks)
{ {
int* blocks = _glfw_realloc(window->preeditAttributeBlocks, sizeof(int) * cblocks); size_t bufsize = sizeof(int) * cblocks;
int* blocks = _glfw_realloc(window->preeditAttributeBlocks,
bufsize);
if (blocks == NULL) if (blocks == NULL)
{ {
@ -627,7 +630,7 @@ static GLFWbool getImmPreedit(_GLFWwindow* window)
_win32ChangeCursorPosition(hIMC, window); _win32ChangeCursorPosition(hIMC, window);
} }
ImmReleaseContext(hWnd, hIMC); ImmReleaseContext(window->win32.handle, hIMC);
return GLFW_TRUE; return GLFW_TRUE;
} }