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
}
public void CompositionChanged()
public void CompositionChanged(string? composition)
{
if (!IsComposing)
{
return;
}
Composition = composition;
if(!IsActive || !Client.SupportsPreedit)
if (!IsActive || !Client.SupportsPreedit)
{
return;
}
var composition = GetCompositionString();
Composition = composition;
Client.SetPreeditText(composition);
}
private string? GetCompositionString()
public string? GetCompositionString(GCS flag)
{
if (!IsComposing)
{
return null;
}
var himc = ImmGetContext(Hwnd);
return ImmGetCompositionString(himc, GCS.GCS_COMPSTR);
return ImmGetCompositionString(himc, flag);
}
~Imm32InputMethod()

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

@ -719,11 +719,13 @@ namespace Avalonia.Win32
{
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:
{
@ -749,10 +751,7 @@ namespace Avalonia.Win32
}
case GCS.GCS_RESULTREADSTR | GCS.GCS_RESULTREADCLAUSE | GCS.GCS_RESULTSTR | GCS.GCS_RESULTCLAUSE:
{
Imm32InputMethod.Current.Composition = previousComposition;
_ignoreWmChar = true;
// Japanese IME sends WM_CHAR after composition has finished.
break;
}
}
@ -780,12 +779,12 @@ namespace Avalonia.Win32
return IntPtr.Zero;
case WindowsMessage.WM_IME_ENDCOMPOSITION:
{
var currentComposition = Imm32InputMethod.Current.Composition;
//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, text);
e = new RawTextInputEventArgs(WindowsKeyboardDevice.Instance, timestamp, Owner, currentComposition);
}
//Cleanup composition state.

Loading…
Cancel
Save