From: Byeongsik Jeon bsjeon@hanmail.net
In winemac.drv, Multiple ime update calls occur during ImeProcessKey. These multiple ime update calls need to be properly merged into ‘data->update’. However, currently win32u/imm.c::post_ime_update() only keeps the last ime update call.
Valid rules are: - The comp_str is discarded when the next ime update call occurs, so it is only valid when the last ime update call has the comp_str. - The result_str is retained even if the next ime update call occurs. - If the next ime update call has the result_str, it is appended after the previous result_str. (e.g. 'r-k-1' or 'r-k-<SPACE>')
Test key sequences are: - "Japanese Romanji" : 'nihongo-<SPACE>-n' - "Korean 2-Set Keyboard" : 'r-k-s-k' - "Korean 2-Set Keyboard" : 'r-k-1" or 'r-k-<SPACE>' --- dlls/win32u/imm.c | 25 +++++++++++++++++++++++-- 1 file changed, 23 insertions(+), 2 deletions(-)
diff --git a/dlls/win32u/imm.c b/dlls/win32u/imm.c index 99dc3e5e225..717dbf43ee6 100644 --- a/dlls/win32u/imm.c +++ b/dlls/win32u/imm.c @@ -440,7 +440,8 @@ static void post_ime_update( HWND hwnd, UINT cursor_pos, WCHAR *comp_str, WCHAR static UINT ime_update_count;
struct imm_thread_data *data = get_imm_thread_data(); - UINT id = -1, comp_len, result_len; + UINT id = -1, comp_len, result_len, prev_result_len; + WCHAR *prev_result_str, *tmp; struct ime_update *update;
TRACE( "hwnd %p, cursor_pos %u, comp_str %s, result_str %s\n", hwnd, cursor_pos, @@ -449,7 +450,25 @@ static void post_ime_update( HWND hwnd, UINT cursor_pos, WCHAR *comp_str, WCHAR comp_len = comp_str ? wcslen( comp_str ) + 1 : 0; result_len = result_str ? wcslen( result_str ) + 1 : 0;
- if (!(update = malloc( offsetof(struct ime_update, buffer[comp_len + result_len]) ))) return; + /* prepend or keep the previous result string, if there was any */ + if (!data->ime_process_vkey || !data->update) prev_result_str = NULL; + else prev_result_str = data->update->result_str; + prev_result_len = prev_result_str ? wcslen( prev_result_str ) + 1 : 0; + + if (!prev_result_len && !result_len) tmp = NULL; + else if (!(tmp = malloc( (prev_result_len + result_len) * sizeof(WCHAR) ))) return; + + if (prev_result_len && result_len) prev_result_len -= 1; /* concat both strings */ + if (prev_result_len) memcpy( tmp, prev_result_str, prev_result_len * sizeof(WCHAR) ); + if (result_len) memcpy( tmp + prev_result_len, result_str, result_len * sizeof(WCHAR) ); + result_len += prev_result_len; + result_str = tmp; + + if (!(update = malloc( offsetof(struct ime_update, buffer[comp_len + result_len]) ))) + { + free( tmp ); + return; + } update->cursor_pos = cursor_pos; update->comp_str = comp_str ? memcpy( update->buffer, comp_str, comp_len * sizeof(WCHAR) ) : NULL; update->result_str = result_str ? memcpy( update->buffer + comp_len, result_str, result_len * sizeof(WCHAR) ) : NULL; @@ -470,6 +489,8 @@ static void post_ime_update( HWND hwnd, UINT cursor_pos, WCHAR *comp_str, WCHAR free( data->update ); data->update = update; } + + free( tmp ); }
static struct ime_update *find_ime_update( WORD vkey, WORD scan )