@ -18,7 +18,8 @@ namespace ICSharpCode.TextEditor
{
{
public Ime ( IntPtr hWnd , Font font )
public Ime ( IntPtr hWnd , Font font )
{
{
hIMEWnd = ImmGetDefaultIMEWnd ( hWnd ) ;
this . hWnd = hWnd ;
this . hIMEWnd = ImmGetDefaultIMEWnd ( hWnd ) ;
this . font = font ;
this . font = font ;
SetIMEWindowFont ( font ) ;
SetIMEWindowFont ( font ) ;
}
}
@ -37,13 +38,24 @@ namespace ICSharpCode.TextEditor
}
}
}
}
public IntPtr HWnd
{
set {
if ( this . hWnd ! = value ) {
this . hWnd = value ;
this . hIMEWnd = ImmGetDefaultIMEWnd ( value ) ;
SetIMEWindowFont ( font ) ;
}
}
}
[ DllImport("imm32.dll") ]
[ DllImport("imm32.dll") ]
private static extern IntPtr ImmGetDefaultIMEWnd ( IntPtr hWnd ) ;
private static extern IntPtr ImmGetDefaultIMEWnd ( IntPtr hWnd ) ;
[ DllImport("user32.dll") ]
[ DllImport("user32.dll") ]
private static extern IntPtr SendMessage ( IntPtr hWnd , int msg , IntPtr wParam , COMPOSITIONFORM lParam ) ;
private static extern int SendMessage ( IntPtr hWnd , int msg , int wParam , COMPOSITIONFORM lParam ) ;
[ DllImport("user32.dll") ]
[ DllImport("user32.dll") ]
private static extern IntPtr SendMessage ( IntPtr hWnd , int msg , IntPtr wParam , LOGFONT lParam ) ;
private static extern int SendMessage ( IntPtr hWnd , int msg , int wParam , [ In , MarshalAs ( UnmanagedType . LPStruct ) ] LOGFONT lParam ) ;
[ StructLayout(LayoutKind.Sequential) ]
[ StructLayout(LayoutKind.Sequential) ]
private class COMPOSITIONFORM
private class COMPOSITIONFORM
@ -71,12 +83,12 @@ namespace ICSharpCode.TextEditor
private const int WM_IME_CONTROL = 0x0283 ;
private const int WM_IME_CONTROL = 0x0283 ;
private const int IMC_SETCOMPOSITIONFONT = 0x000a ;
private const int IMC_SETCOMPOSITIONWINDOW = 0x000c ;
private const int IMC_SETCOMPOSITIONWINDOW = 0x000c ;
private IntPtr hIMEWnd ;
private IntPtr hIMEWnd ;
private IntPtr hWnd ;
private const int CFS_POINT = 0x0002 ;
private const int CFS_POINT = 0x0002 ;
[ StructLayout(LayoutKind.Sequential, CharSet=CharSet.Auto ) ]
[ StructLayout(LayoutKind.Sequential) ]
private class LOGFONT
private class LOGFONT
{
{
public int lfHeight = 0 ;
public int lfHeight = 0 ;
@ -94,25 +106,22 @@ namespace ICSharpCode.TextEditor
public byte lfPitchAndFamily = 0 ;
public byte lfPitchAndFamily = 0 ;
[ MarshalAs(UnmanagedType.ByValTStr, SizeConst=32) ] public string lfFaceName = null ;
[ MarshalAs(UnmanagedType.ByValTStr, SizeConst=32) ] public string lfFaceName = null ;
}
}
private const int IMC_SETCOMPOSITIONFONT = 0x000a ;
const byte FF_MODERN = 4 8 ;
const byte FIXED_PITCH = 1 ;
private void SetIMEWindowFont ( Font f )
private void SetIMEWindowFont ( Font f )
{
{
LOGFONT lf = new LOGFONT ( ) ;
LOGFONT lf = new LOGFONT ( ) ;
f . ToLogFont ( lf ) ;
f . ToLogFont ( lf ) ;
lf . lfPitchAndFamily = FIXED_PITCH | FF_MODERN ;
lf . lfFaceName = f . Name ; // This is very important! "Font.ToLogFont" Method sets invalid value to LOGFONT.lfFaceName
SendMessage (
SendMessage (
hIMEWnd ,
hIMEWnd ,
WM_IME_CONTROL ,
WM_IME_CONTROL ,
new IntPtr ( IMC_SETCOMPOSITIONFONT ) ,
IMC_SETCOMPOSITIONFONT ,
lf
lf
) ;
) ;
}
}
public void SetIMEWindowLocation ( int x , int y )
public void SetIMEWindowLocation ( int x , int y )
{
{
@ -128,7 +137,7 @@ namespace ICSharpCode.TextEditor
SendMessage (
SendMessage (
hIMEWnd ,
hIMEWnd ,
WM_IME_CONTROL ,
WM_IME_CONTROL ,
new IntPtr ( IMC_SETCOMPOSITIONWINDOW ) ,
IMC_SETCOMPOSITIONWINDOW ,
lParam
lParam
) ;
) ;
}
}