Browse Source

implemented SetCompositionFont: now the IME font size should be the same as in the editor

pull/28/head
Siegfried Pammer 13 years ago
parent
commit
22dedf2601
  1. 42
      src/Libraries/AvalonEdit/ICSharpCode.AvalonEdit/Editing/ImeNativeWrapper.cs
  2. 2
      src/Libraries/AvalonEdit/ICSharpCode.AvalonEdit/Editing/ImeSupport.cs

42
src/Libraries/AvalonEdit/ICSharpCode.AvalonEdit/Editing/ImeNativeWrapper.cs

@ -49,23 +49,23 @@ namespace ICSharpCode.AvalonEdit.Editing
public int bottom; public int bottom;
} }
[StructLayout(LayoutKind.Sequential, CharSet=CharSet.Auto)] [StructLayout(LayoutKind.Sequential, CharSet=CharSet.Unicode)]
class LOGFONT struct LOGFONT
{ {
public int lfHeight = 0; public int lfHeight;
public int lfWidth = 0; public int lfWidth;
public int lfEscapement = 0; public int lfEscapement;
public int lfOrientation = 0; public int lfOrientation;
public int lfWeight = 0; public int lfWeight;
public byte lfItalic = 0; public byte lfItalic;
public byte lfUnderline = 0; public byte lfUnderline;
public byte lfStrikeOut = 0; public byte lfStrikeOut;
public byte lfCharSet = 0; public byte lfCharSet;
public byte lfOutPrecision = 0; public byte lfOutPrecision;
public byte lfClipPrecision = 0; public byte lfClipPrecision;
public byte lfQuality = 0; public byte lfQuality;
public byte lfPitchAndFamily = 0; public byte lfPitchAndFamily;
[MarshalAs(UnmanagedType.ByValTStr, SizeConst=32)] public string lfFaceName = null; [MarshalAs(UnmanagedType.ByValTStr, SizeConst=32)] public string lfFaceName;
} }
const int CPS_CANCEL = 0x4; const int CPS_CANCEL = 0x4;
@ -97,7 +97,7 @@ namespace ICSharpCode.AvalonEdit.Editing
[DllImport("imm32.dll")] [DllImport("imm32.dll")]
[return: MarshalAs(UnmanagedType.Bool)] [return: MarshalAs(UnmanagedType.Bool)]
static extern bool ImmSetCompositionWindow(IntPtr hIMC, ref CompositionForm form); static extern bool ImmSetCompositionWindow(IntPtr hIMC, ref CompositionForm form);
[DllImport("imm32.dll")] [DllImport("imm32.dll", CharSet = CharSet.Unicode)]
[return: MarshalAs(UnmanagedType.Bool)] [return: MarshalAs(UnmanagedType.Bool)]
static extern bool ImmSetCompositionFont(IntPtr hIMC, ref LOGFONT font); static extern bool ImmSetCompositionFont(IntPtr hIMC, ref LOGFONT font);
[DllImport("imm32.dll")] [DllImport("imm32.dll")]
@ -157,9 +157,11 @@ namespace ICSharpCode.AvalonEdit.Editing
{ {
if (textArea == null) if (textArea == null)
throw new ArgumentNullException("textArea"); throw new ArgumentNullException("textArea");
// LOGFONT font = new LOGFONT(); LOGFONT lf = new LOGFONT();
// ImmGetCompositionFont(hIMC, out font); Rect characterBounds = textArea.TextView.GetCharacterBounds(textArea.Caret.Position, source);
return false; lf.lfFaceName = textArea.FontFamily.Source;
lf.lfHeight = (int)characterBounds.Height;
return ImmSetCompositionFont(hIMC, ref lf);
} }
static Rect GetBounds(this TextView textView, HwndSource source) static Rect GetBounds(this TextView textView, HwndSource source)

2
src/Libraries/AvalonEdit/ICSharpCode.AvalonEdit/Editing/ImeSupport.cs

@ -70,7 +70,6 @@ namespace ICSharpCode.AvalonEdit.Editing
//currentContext = ImeNativeWrapper.ImmCreateContext(); //currentContext = ImeNativeWrapper.ImmCreateContext();
//previousContext = ImeNativeWrapper.AssociateContext(hwndSource, currentContext); //previousContext = ImeNativeWrapper.AssociateContext(hwndSource, currentContext);
currentContext = ImeNativeWrapper.GetContext(hwndSource); currentContext = ImeNativeWrapper.GetContext(hwndSource);
// ImeNativeWrapper.SetCompositionFont(hwndSource, currentContext, textArea);
hwndSource.AddHook(WndProc); hwndSource.AddHook(WndProc);
// UpdateCompositionWindow() will be called by the caret becoming visible // UpdateCompositionWindow() will be called by the caret becoming visible
@ -109,6 +108,7 @@ namespace ICSharpCode.AvalonEdit.Editing
public void UpdateCompositionWindow() public void UpdateCompositionWindow()
{ {
if (currentContext != IntPtr.Zero) { if (currentContext != IntPtr.Zero) {
ImeNativeWrapper.SetCompositionFont(hwndSource, currentContext, textArea);
ImeNativeWrapper.SetCompositionWindow(hwndSource, currentContext, textArea); ImeNativeWrapper.SetCompositionWindow(hwndSource, currentContext, textArea);
} }
} }

Loading…
Cancel
Save