Browse Source

Trz to fix Japanese IME

pull/9526/head
Benedikt Stebner 4 years ago
parent
commit
c5189bd6f6
  1. 22
      src/Windows/Avalonia.Win32/Input/Imm32InputMethod.cs
  2. 21
      src/Windows/Avalonia.Win32/WindowImpl.AppWndProc.cs

22
src/Windows/Avalonia.Win32/Input/Imm32InputMethod.cs

@ -271,30 +271,28 @@ namespace Avalonia.Win32.Input
// we're skipping this. not usable on windows // we're skipping this. not usable on windows
} }
public void CompositionChanged() public void CompositionChanged(string? composition)
{ {
if (!IsComposing) Composition = composition;
{
return;
}
if(!IsActive || !Client.SupportsPreedit) if (!IsActive || !Client.SupportsPreedit)
{ {
return; return;
} }
var composition = GetCompositionString();
Composition = composition;
Client.SetPreeditText(composition); Client.SetPreeditText(composition);
} }
private string? GetCompositionString() public string? GetCompositionString(GCS flag)
{ {
if (!IsComposing)
{
return null;
}
var himc = ImmGetContext(Hwnd); var himc = ImmGetContext(Hwnd);
return ImmGetCompositionString(himc, GCS.GCS_COMPSTR); return ImmGetCompositionString(himc, flag);
} }
~Imm32InputMethod() ~Imm32InputMethod()

21
src/Windows/Avalonia.Win32/WindowImpl.AppWndProc.cs

@ -719,11 +719,13 @@ namespace Avalonia.Win32
{ {
var previousComposition = Imm32InputMethod.Current.Composition; var previousComposition = Imm32InputMethod.Current.Composition;
Imm32InputMethod.Current.CompositionChanged(); var flags = (GCS)ToInt32(lParam);
var gcs = (GCS)ToInt32(lParam); var currentComposition = Imm32InputMethod.Current.GetCompositionString(GCS.GCS_COMPSTR);
switch (gcs) Imm32InputMethod.Current.CompositionChanged(currentComposition);
switch (flags)
{ {
case GCS.GCS_RESULTSTR: case GCS.GCS_RESULTSTR:
{ {
@ -749,10 +751,7 @@ namespace Avalonia.Win32
} }
case GCS.GCS_RESULTREADSTR | GCS.GCS_RESULTREADCLAUSE | GCS.GCS_RESULTSTR | GCS.GCS_RESULTCLAUSE: case GCS.GCS_RESULTREADSTR | GCS.GCS_RESULTREADCLAUSE | GCS.GCS_RESULTSTR | GCS.GCS_RESULTCLAUSE:
{ {
Imm32InputMethod.Current.Composition = previousComposition; // Japanese IME sends WM_CHAR after composition has finished.
_ignoreWmChar = true;
break; break;
} }
} }
@ -780,12 +779,12 @@ namespace Avalonia.Win32
return IntPtr.Zero; return IntPtr.Zero;
case WindowsMessage.WM_IME_ENDCOMPOSITION: case WindowsMessage.WM_IME_ENDCOMPOSITION:
{ {
var currentComposition = Imm32InputMethod.Current.Composition;
//In case composition has not been comitted yet we need to do that here. //In case composition has not been comitted yet we need to do that here.
if (!string.IsNullOrEmpty(Imm32InputMethod.Current.Composition)) if (!string.IsNullOrEmpty(currentComposition))
{ {
var text = Imm32InputMethod.Current.Composition; e = new RawTextInputEventArgs(WindowsKeyboardDevice.Instance, timestamp, Owner, currentComposition);
e = new RawTextInputEventArgs(WindowsKeyboardDevice.Instance, timestamp, Owner, text);
} }
//Cleanup composition state. //Cleanup composition state.

Loading…
Cancel
Save