https://git.reactos.org/?p=reactos.git;a=commitdiff;h=31f3eb1d57db73b895984a5c11c33899f07d00f7

commit 31f3eb1d57db73b895984a5c11c33899f07d00f7
Author:     Katayama Hirofumi MZ <[email protected]>
AuthorDate: Fri Apr 28 08:28:57 2023 +0900
Commit:     GitHub <[email protected]>
CommitDate: Fri Apr 28 08:28:57 2023 +0900

    [RICHED20] RichEdit: CompForm and CandForm (#5257)
    
    Correctly display the composition window and the candidate window.
    - At update_caret function, set the position and font of the composition 
window.
    - We don't use internal composition string. Rely on the composition window.
    - Improve WM_IME_SETCONTEXT, WM_IME_CONTROL, WM_IME_SELECT, 
WM_IME_STARTCOMPOSITION, WM_IME_COMPOSITION and WM_IME_ENDCOMPOSITION message 
handlings.
    CORE-11700
---
 dll/win32/riched20/caret.c   | 45 ++++++++++++++++++++++++++++++++++
 dll/win32/riched20/editor.c  | 57 ++++++++++++++++++++++++++++++++++++++++++++
 dll/win32/riched20/editstr.h |  2 ++
 3 files changed, 104 insertions(+)

diff --git a/dll/win32/riched20/caret.c b/dll/win32/riched20/caret.c
index 212c9e9f992..96a95872c2d 100644
--- a/dll/win32/riched20/caret.c
+++ b/dll/win32/riched20/caret.c
@@ -310,6 +310,51 @@ void update_caret(ME_TextEditor *editor)
   }
   else
     hide_caret(editor);
+#ifdef __REACTOS__
+  if (ImmIsIME(GetKeyboardLayout(0)))
+  {
+    HIMC hIMC = ImmGetContext(editor->hWnd);
+    if (hIMC)
+    {
+      CHARFORMAT2W fmt;
+      LOGFONTW lf;
+      COMPOSITIONFORM CompForm;
+      POINT pt = { x, y };
+
+      CompForm.ptCurrentPos = pt;
+      if (editor->styleFlags & ES_MULTILINE)
+      {
+        CompForm.dwStyle = CFS_RECT;
+        CompForm.rcArea = editor->rcFormat;
+      }
+      else
+      {
+        CompForm.dwStyle = CFS_POINT;
+        SetRectEmpty(&CompForm.rcArea);
+      }
+      ImmSetCompositionWindow(hIMC, &CompForm);
+
+      fmt.cbSize = sizeof(fmt);
+      ME_GetSelectionCharFormat(editor, &fmt);
+
+      ZeroMemory(&lf, sizeof(lf));
+      lf.lfCharSet = DEFAULT_CHARSET;
+      if (fmt.dwMask & CFM_SIZE)
+      {
+        HDC hdc = CreateCompatibleDC(NULL);
+        lf.lfHeight = -MulDiv(fmt.yHeight, GetDeviceCaps(hdc, LOGPIXELSY), 
1440);
+        DeleteDC(hdc);
+      }
+      if (fmt.dwMask & CFM_CHARSET)
+        lf.lfCharSet = fmt.bCharSet;
+      if (fmt.dwMask & CFM_FACE)
+        lstrcpynW(lf.lfFaceName, fmt.szFaceName, ARRAY_SIZE(lf.lfFaceName));
+      ImmSetCompositionFontW(hIMC, &lf);
+
+      ImmReleaseContext(editor->hWnd, hIMC);
+    }
+  }
+#endif
 }
 
 BOOL ME_InternalDeleteText(ME_TextEditor *editor, ME_Cursor *start,
diff --git a/dll/win32/riched20/editor.c b/dll/win32/riched20/editor.c
index 5ad25869997..bf13c417542 100644
--- a/dll/win32/riched20/editor.c
+++ b/dll/win32/riched20/editor.c
@@ -233,6 +233,9 @@
 #include "shlwapi.h"
 #include "rtf.h"
 #include "imm.h"
+#ifdef __REACTOS__
+  #include "immdev.h"
+#endif
 #include "res.h"
 
 #ifdef __REACTOS__
@@ -4103,6 +4106,14 @@ LRESULT ME_HandleMessage(ME_TextEditor *editor, UINT 
msg, WPARAM wParam,
     ME_UpdateScrollBar(editor);
     if (bRepaint)
       ME_Repaint(editor);
+#ifdef __REACTOS__
+    if (ImmIsIME(GetKeyboardLayout(0)))
+    {
+      HIMC hIMC = ImmGetContext(editor->hWnd);
+      ImmSetCompositionFontW(hIMC, &lf);
+      ImmReleaseContext(editor->hWnd, hIMC);
+    }
+#endif
     return 0;
   }
   case WM_SETTEXT:
@@ -4779,18 +4790,52 @@ LRESULT ME_HandleMessage(ME_TextEditor *editor, UINT 
msg, WPARAM wParam,
     ME_RewrapRepaint(editor);
     goto do_default;
   }
+#ifndef __REACTOS__
   /* IME messages to make richedit controls IME aware */
+#endif
   case WM_IME_SETCONTEXT:
+#ifdef __REACTOS__
+  {
+    if (FALSE) /* FIXME: Condition */
+      lParam &= ~ISC_SHOWUICOMPOSITIONWINDOW;
+
+    if (wParam)
+    {
+      HIMC hIMC = ImmGetContext(editor->hWnd);
+      LPINPUTCONTEXTDX pIC = (LPINPUTCONTEXTDX)ImmLockIMC(hIMC);
+      if (pIC)
+      {
+        pIC->dwUIFlags &= ~0x40000;
+        ImmUnlockIMC(hIMC);
+      }
+      if (FALSE) /* FIXME: Condition */
+        ImmNotifyIME(hIMC, NI_COMPOSITIONSTR, CPS_CANCEL, 0);
+      ImmReleaseContext(editor->hWnd, hIMC);
+    }
+
+    return DefWindowProcW(editor->hWnd, msg, wParam, lParam);
+  }
+#endif
   case WM_IME_CONTROL:
+#ifdef __REACTOS__
+    return DefWindowProcW(editor->hWnd, msg, wParam, lParam);
+#endif
   case WM_IME_SELECT:
+#ifdef __REACTOS__
+    return DefWindowProcW(editor->hWnd, msg, wParam, lParam);
+#endif
   case WM_IME_COMPOSITIONFULL:
     return 0;
   case WM_IME_STARTCOMPOSITION:
   {
+#ifdef __REACTOS__
+    return DefWindowProcW(editor->hWnd, msg, wParam, lParam);
+#else
     editor->imeStartIndex=ME_GetCursorOfs(&editor->pCursors[0]);
     ME_DeleteSelection(editor);
     ME_CommitUndo(editor);
     ME_UpdateRepaint(editor, FALSE);
+#endif
     return 0;
   }
   case WM_IME_COMPOSITION:
@@ -4813,23 +4858,35 @@ LRESULT ME_HandleMessage(ME_TextEditor *editor, UINT 
msg, WPARAM wParam,
         lpCompStr = HeapAlloc(GetProcessHeap(),0,dwBufLen + sizeof(WCHAR));
         ImmGetCompositionStringW(hIMC, dwIndex, lpCompStr, dwBufLen);
         lpCompStr[dwBufLen/sizeof(WCHAR)] = 0;
+#ifndef __REACTOS__
         
ME_InsertTextFromCursor(editor,0,lpCompStr,dwBufLen/sizeof(WCHAR),style);
+#endif
         HeapFree(GetProcessHeap(), 0, lpCompStr);
 
+#ifndef __REACTOS__
         if (dwIndex == GCS_COMPSTR)
           set_selection_cursors(editor,editor->imeStartIndex,
                           editor->imeStartIndex + dwBufLen/sizeof(WCHAR));
+#endif
     }
     ME_ReleaseStyle(style);
     ME_CommitUndo(editor);
     ME_UpdateRepaint(editor, FALSE);
+#ifdef __REACTOS__
+    return DefWindowProcW(editor->hWnd, msg, wParam, lParam);
+#else
     return 0;
+#endif
   }
   case WM_IME_ENDCOMPOSITION:
   {
+#ifdef __REACTOS__
+    return DefWindowProcW(editor->hWnd, msg, wParam, lParam);
+#else
     ME_DeleteSelection(editor);
     editor->imeStartIndex=-1;
     return 0;
+#endif
   }
   case EM_GETOLEINTERFACE:
   {
diff --git a/dll/win32/riched20/editstr.h b/dll/win32/riched20/editstr.h
index 608901a5e22..337750c4052 100644
--- a/dll/win32/riched20/editstr.h
+++ b/dll/win32/riched20/editstr.h
@@ -426,8 +426,10 @@ typedef struct tagME_TextEditor
   WCHAR cPasswordMask;
   BOOL bHaveFocus;
   BOOL bDialogMode; /* Indicates that we are inside a dialog window */
+#ifndef __REACTOS__
   /*for IME */
   int imeStartIndex;
+#endif
   DWORD selofs; /* The size of the selection bar on the left side of control */
   ME_SelectionType nSelectionType;
   ME_DisplayItem *first_marked_para;

Reply via email to