*** src/gui_w32.c~ Thu Jul 17 12:38:17 2003 --- src/gui_w32.c Tue Jul 22 12:30:19 2003 *************** *** 243,248 **** --- 243,249 ---- HINSTANCE hLibImm = NULL; LONG (WINAPI *pImmGetCompositionStringA)(HIMC, DWORD, LPVOID, DWORD); LONG (WINAPI *pImmGetCompositionStringW)(HIMC, DWORD, LPVOID, DWORD); + BOOL (WINAPI *pImmSetCompositionStringA)(HIMC, DWORD, LPVOID, DWORD, LPVOID, DWORD); HIMC (WINAPI *pImmGetContext)(HWND); HIMC (WINAPI *pImmAssociateContext)(HWND, HIMC); BOOL (WINAPI *pImmReleaseContext)(HWND, HIMC); *************** *** 256,261 **** --- 257,263 ---- #else # define pImmGetCompositionStringA ImmGetCompositionStringA # define pImmGetCompositionStringW ImmGetCompositionStringW + # define pImmSetCompositionStringA ImmSetCompositionStringA # define pImmGetContext ImmGetContext # define pImmAssociateContext ImmAssociateContext # define pImmReleaseContext ImmReleaseContext *************** *** 267,272 **** --- 269,297 ---- # define pImmGetConversionStatus ImmGetConversionStatus #endif + #if defined(FEAT_MBYTE_IME) + # ifndef RECONVERTSTRING + typedef struct tagRECONVERTSTRING { + DWORD dwSize; + DWORD dwVersion; + DWORD dwStrLen; + DWORD dwStrOffset; + DWORD dwCompStrLen; + DWORD dwCompStrOffset; + DWORD dwTargetStrLen; + DWORD dwTargetStrOffset; + } RECONVERTSTRING, *PRECONVERTSTRING, NEAR *NPRECONVERTSTRING, FAR *LPRECONVERTSTRING; + #endif + #ifndef WM_IME_REQUEST + # define WM_IME_REQUEST 0x0288 + #endif + #ifndef IMR_RECONVERTSTRING + # define IMR_RECONVERTSTRING 0x0004 + #endif + + static LRESULT _OnImeReConvert(HWND hWnd, DWORD lParam); + #endif + #ifndef ETO_IGNORELANGUAGE # define ETO_IGNORELANGUAGE 0x1000 #endif *************** *** 727,732 **** --- 752,761 ---- if (!_OnImeComposition(hwnd, wParam, lParam)) return DefWindowProc(hwnd, uMsg, wParam, lParam); break; + case WM_IME_REQUEST: + if (wParam == IMR_RECONVERTSTRING && VIsual_active) + return _OnImeReConvert(hwnd, (DWORD)lParam); + break; #endif default: *************** *** 1223,1228 **** --- 1252,1348 ---- } /* + * handle reconverting + */ + static LRESULT + _OnImeReConvert(HWND hWnd, DWORD lParam) + { + HIMC hIMC; + linenr_T lnum; + char_u *ptr, *org; + pos_T start_visual, end_visual; + garray_T ga; + LRESULT res = 0; + LPWSTR wbuf = NULL; + INT len; + RECONVERTSTRING* pReconv = (RECONVERTSTRING*)lParam; + + if (lt(curwin->w_cursor, VIsual)) + { + start_visual = curwin->w_cursor; + end_visual = VIsual; + } + else + { + start_visual = VIsual; + end_visual = curwin->w_cursor; + } + end_visual.col += + (*mb_ptr2len_check)(ml_get_buf(curbuf, end_visual.lnum, FALSE) + + end_visual.col); + ga_init(&ga); + ga.ga_itemsize = 1; + ga.ga_growsize = 40; + for(lnum = start_visual.lnum; lnum <= end_visual.lnum; lnum++) + { + org = ptr = vim_strsave(ml_get_buf(curbuf, lnum, FALSE)); + if (!ptr) + break; + if (VIsual_mode == 'v') + { + if (lnum == start_visual.lnum) + ptr += start_visual.col; + if (lnum == end_visual.lnum && end_visual.col < STRLEN(org)) + *(org + end_visual.col) = 0; + } + + ga_concat(&ga, ptr); + + vim_free(org); + } + + len = STRLEN(ga.ga_data); + if (pReconv) + { + if (pImmGetContext && (hIMC = pImmGetContext(hWnd)) != (HIMC)0) + { + colnr_T imecol; + linenr_T imerow; + pos_T ime_cursor; + ime_cursor = start_visual; + getvcol(curwin, &ime_cursor, &imecol, NULL, NULL); + imerow = gui.row + (start_visual.lnum - end_visual.lnum); + if (imerow < 0) + imerow = 0; + im_set_position(imerow, imecol); + + STRCPY((char*)pReconv + sizeof(RECONVERTSTRING), ga.ga_data); + + pReconv->dwStrLen = len; + pReconv->dwStrOffset = sizeof(RECONVERTSTRING); + pReconv->dwTargetStrLen = 0; + pReconv->dwTargetStrOffset = 0; + pReconv->dwCompStrOffset = 0; + pReconv->dwCompStrLen = len; + + if (pImmSetCompositionStringA( + hIMC, + SCS_QUERYRECONVERTSTRING, + pReconv, sizeof(RECONVERTSTRING), NULL, 0)) + { + (void)ins_typebuf("c", REMAP_NONE, 0, FALSE, FALSE); + curbuf->b_p_iminsert = B_IMODE_IM; + } + + pImmReleaseContext(hWnd, hIMC); + } + } + res = sizeof(RECONVERTSTRING) + len + 1; + + ga_clear(&ga); + return res; + } + /* * handle WM_IME_NOTIFY message */ static LRESULT *************** *** 3297,3302 **** --- 3427,3434 ---- = (void *)GetProcAddress(hLibImm, "ImmGetCompositionStringA"); pImmGetCompositionStringW = (void *)GetProcAddress(hLibImm, "ImmGetCompositionStringW"); + pImmSetCompositionStringA + = (void *)GetProcAddress(hLibImm, "ImmSetCompositionStringA"); pImmGetContext = (void *)GetProcAddress(hLibImm, "ImmGetContext"); pImmAssociateContext *************** *** 3318,3323 **** --- 3450,3456 ---- if ( pImmGetCompositionStringA == NULL || pImmGetCompositionStringW == NULL + || pImmSetCompositionStringA == NULL || pImmGetContext == NULL || pImmAssociateContext == NULL || pImmReleaseContext == NULL