From 599a1a98ecafee58578e8c48813746c0059ef791 Mon Sep 17 00:00:00 2001 From: Takuro Ashie Date: Fri, 15 Apr 2022 13:04:01 +0900 Subject: [PATCH] Win32: Fix style * Remove needless braces * Add spaces * Use C89 style variable declarations --- src/win32_window.c | 29 +++++++++++++++-------------- 1 file changed, 15 insertions(+), 14 deletions(-) diff --git a/src/win32_window.c b/src/win32_window.c index 8c23279c..891e8f70 100644 --- a/src/win32_window.c +++ b/src/win32_window.c @@ -854,25 +854,30 @@ static LRESULT CALLBACK windowProc(HWND hWnd, UINT uMsg, WPARAM wParam, LPARAM l LONG preeditTextLength = ImmGetCompositionStringW(hIMC, GCS_COMPSTR, NULL, 0); LONG attrLength = ImmGetCompositionString(hIMC, GCS_COMPATTR, NULL, 0); LONG clauseLength = ImmGetCompositionString(hIMC, GCS_COMPCLAUSE, NULL, 0); + if (preeditTextLength > 0) { - // get preedit data + int i; + int ctext = window->ctext; + int cblocks = window->cblocks; + int focusedBlock = 0; int length = preeditTextLength / sizeof(WCHAR); LPWSTR buffer = (LPWSTR) _glfw_calloc(preeditTextLength, 1); LPSTR attributes = (LPSTR) _glfw_calloc(attrLength, 1); DWORD *clauses = (DWORD*) _glfw_calloc(clauseLength, 1); + + // get preedit data ImmGetCompositionStringW(hIMC, GCS_COMPSTR, buffer, preeditTextLength); ImmGetCompositionString(hIMC, GCS_COMPATTR, attributes, attrLength); ImmGetCompositionString(hIMC, GCS_COMPCLAUSE, clauses, clauseLength); + // store preedit text - int ctext = window->ctext; while (ctext < length + 1) - { ctext = (ctext == 0) ? 1 : ctext * 2; - } if (ctext != window->ctext) { unsigned int* preeditText = _glfw_realloc(window->preeditText, sizeof(unsigned int) * ctext); + if (preeditText == NULL) { _glfw_free(buffer); @@ -885,24 +890,20 @@ static LRESULT CALLBACK windowProc(HWND hWnd, UINT uMsg, WPARAM wParam, LPARAM l } window->ntext = length; window->preeditText[length] = 0; - int i; - for (i=0; i < length; i++) - { + for (i = 0; i < length; i++) window->preeditText[i] = buffer[i]; - } + // store blocks window->nblocks = clauseLength / sizeof(DWORD) - 1; // last element of clauses is a block count, but // text length is convenient. clauses[window->nblocks] = length; - int cblocks = window->cblocks; while (cblocks < window->nblocks) - { cblocks = (cblocks == 0) ? 1 : cblocks * 2; - } if (cblocks != window->cblocks) { int* blocks = _glfw_realloc(window->preeditAttributeBlocks, sizeof(int) * cblocks); + if (blocks == NULL) { _glfw_free(buffer); @@ -913,21 +914,21 @@ static LRESULT CALLBACK windowProc(HWND hWnd, UINT uMsg, WPARAM wParam, LPARAM l window->preeditAttributeBlocks = blocks; window->cblocks = cblocks; } - int focusedBlock = 0; for (i = 0; i < window->nblocks; i++) { window->preeditAttributeBlocks[i] = clauses[i + 1] - clauses[i]; if (attributes[clauses[i]] != ATTR_CONVERTED) - { focusedBlock = i; - } } + _glfw_free(buffer); _glfw_free(attributes); _glfw_free(clauses); + _glfwInputPreedit(window, focusedBlock); _win32ChangeCursorPosition(hIMC, window); } + ImmReleaseContext(hWnd, hIMC); return TRUE; }