From c03125a1be04d4a2c9f047d92a32b4eb6869ae68 Mon Sep 17 00:00:00 2001 From: Aric Stewart Date: Wed, 27 Jun 2007 07:57:51 -0500 Subject: [PATCH] riched20: Make richedit control IME aware. --- dlls/riched20/Makefile.in | 2 +- dlls/riched20/editor.c | 59 +++++++++++++++++++++++++++++++++++++++ dlls/riched20/editstr.h | 2 ++ 3 files changed, 62 insertions(+), 1 deletion(-) diff --git a/dlls/riched20/Makefile.in b/dlls/riched20/Makefile.in index 87feccd0603..6b974e5b7a1 100644 --- a/dlls/riched20/Makefile.in +++ b/dlls/riched20/Makefile.in @@ -4,7 +4,7 @@ SRCDIR = @srcdir@ VPATH = @srcdir@ MODULE = riched20.dll IMPORTLIB = libriched20.$(IMPLIBEXT) -IMPORTS = ole32 user32 gdi32 kernel32 +IMPORTS = ole32 imm32 user32 gdi32 kernel32 EXTRALIBS = -luuid C_SRCS = \ diff --git a/dlls/riched20/editor.c b/dlls/riched20/editor.c index b83fb415d1c..4cdb54a1be2 100644 --- a/dlls/riched20/editor.c +++ b/dlls/riched20/editor.c @@ -227,6 +227,7 @@ #define NO_SHLWAPI_STREAM #include "shlwapi.h" #include "rtf.h" +#include "imm.h" #define STACK_SIZE_DEFAULT 100 #define STACK_SIZE_MAX 1000 @@ -2515,6 +2516,64 @@ static LRESULT RichEditWndProc_common(HWND hWnd, UINT msg, WPARAM wParam, ME_RewrapRepaint(editor); return DefWindowProcW(hWnd, msg, wParam, lParam); } + /* IME messages to make richedit controls IME aware */ + case WM_IME_SETCONTEXT: + case WM_IME_CONTROL: + case WM_IME_SELECT: + case WM_IME_COMPOSITIONFULL: + return 0; + case WM_IME_STARTCOMPOSITION: + { + editor->imeStartIndex=ME_GetCursorOfs(editor,0); + ME_DeleteSelection(editor); + ME_CommitUndo(editor); + ME_UpdateRepaint(editor); + return 0; + } + case WM_IME_COMPOSITION: + { + HIMC hIMC; + + ME_Style *style = ME_GetInsertStyle(editor, 0); + hIMC = ImmGetContext(hWnd); + ME_DeleteSelection(editor); + ME_CommitUndo(editor); + ME_SaveTempStyle(editor); + if (lParam & GCS_RESULTSTR) + { + LPWSTR lpCompStr = NULL; + DWORD dwBufLen; + + dwBufLen = ImmGetCompositionStringW(hIMC, GCS_RESULTSTR, NULL, 0); + lpCompStr = HeapAlloc(GetProcessHeap(),0,dwBufLen + sizeof(WCHAR)); + ImmGetCompositionStringW(hIMC, GCS_RESULTSTR, lpCompStr, dwBufLen); + lpCompStr[dwBufLen/sizeof(WCHAR)] = 0; + ME_InsertTextFromCursor(editor,0,lpCompStr,dwBufLen/sizeof(WCHAR),style); + } + else if (lParam & GCS_COMPSTR) + { + LPWSTR lpCompStr = NULL; + DWORD dwBufLen; + + dwBufLen = ImmGetCompositionStringW(hIMC, GCS_COMPSTR, NULL, 0); + lpCompStr = HeapAlloc(GetProcessHeap(),0,dwBufLen + sizeof(WCHAR)); + ImmGetCompositionStringW(hIMC, GCS_COMPSTR, lpCompStr, dwBufLen); + lpCompStr[dwBufLen/sizeof(WCHAR)] = 0; + + ME_InsertTextFromCursor(editor,0,lpCompStr,dwBufLen/sizeof(WCHAR),style); + ME_SetSelection(editor,editor->imeStartIndex, + editor->imeStartIndex + dwBufLen/sizeof(WCHAR)); + } + ME_ReleaseStyle(style); + ME_UpdateRepaint(editor); + return 0; + } + case WM_IME_ENDCOMPOSITION: + { + ME_DeleteSelection(editor); + editor->imeStartIndex=-1; + return 0; + } case EM_GETOLEINTERFACE: { LPVOID *ppvObj = (LPVOID*) lParam; diff --git a/dlls/riched20/editstr.h b/dlls/riched20/editstr.h index ee5dfe32944..7bb91d52445 100644 --- a/dlls/riched20/editstr.h +++ b/dlls/riched20/editstr.h @@ -322,6 +322,8 @@ typedef struct tagME_TextEditor BOOL AutoURLDetect_bEnable; WCHAR cPasswordMask; BOOL bHaveFocus; + /*for IME */ + int imeStartIndex; } ME_TextEditor; typedef struct tagME_Context