protected override void WndProc(ref Message m) { if (m.Msg == (int)Win32.WMessages.WM_CHAR) { int inputChar = m.WParam.ToInt32(); if (inputChar != 8 && // backspace inputChar != 13 && // enter inputChar != 27 // escape //&& inputChar != '\t' // tab ) { inputChar = this.owner.currentWorksheet.RaiseCellEditCharInputed(m.WParam.ToInt32()); } m.WParam = new IntPtr(inputChar); base.WndProc(ref m); return; } else if (m.Msg == (int)Win32.WMessages.WM_IME_STARTCOMPOSITION) { CheckAndUpdateWidth(); } else if (m.Msg == (int)Win32.WMessages.WM_IME_COMPOSITION) { IntPtr ime = Win32.ImmGetContext(this.Handle); int strLen = Win32.ImmGetCompositionString(ime, (int)Win32.GCS.GCS_COMPREADATTR, null, 0); StringBuilder sb = new StringBuilder(strLen); Win32.ImmGetCompositionString(ime, (int)Win32.GCS.GCS_COMPREADATTR, sb, strLen); Win32.COMPOSITIONFORM com = new Win32.COMPOSITIONFORM(); Win32.ImmGetCompositionWindow(ime, ref com); com.rcArea = new System.Drawing.Rectangle(0, 0, 300, Height); bool b = Win32.ImmSetCompositionWindow(ime, ref com); Win32.ImmReleaseContext(this.Handle, ime); } base.WndProc(ref m); }
//IMEの位置合わせなど。日本語入力開始時、現在のキャレット位置からIMEをスタートさせる。 private void AdjustIMEComposition() { TerminalDocument document = GetDocument(); IntPtr hIMC = Win32.ImmGetContext(this.Handle); RenderProfile prof = GetRenderProfile(); //フォントのセットは1回やればよいのか? Win32.LOGFONT lf = new Win32.LOGFONT(); prof.CalcFont(null, CharGroup.Zenkaku).ToLogFont(lf); Win32.ImmSetCompositionFont(hIMC, lf); Win32.COMPOSITIONFORM form = new Win32.COMPOSITIONFORM(); form.dwStyle = Win32.CFS_POINT; Win32.SystemMetrics sm = GEnv.SystemMetrics; //Debug.WriteLine(String.Format("{0} {1} {2}", document.CaretColumn, charwidth, document.CurrentLine.CharPosToDisplayPos(document.CaretColumn))); form.ptCurrentPos.x = sm.ControlBorderWidth + (int)(prof.Pitch.Width * (document.CaretColumn)); form.ptCurrentPos.y = sm.ControlBorderHeight + (int)((prof.Pitch.Height + prof.LineSpacing) * (document.CurrentLineNumber - document.TopLineNumber)); bool r = Win32.ImmSetCompositionWindow(hIMC, ref form); Debug.Assert(r); Win32.ImmReleaseContext(this.Handle, hIMC); }
//IME�̈ʒu���킹�ȂǁB���{����͊J�n���A���݂̃L�����b�g�ʒu����IME��X�^�[�g������B private void AdjustIMEComposition() { TerminalDocument document = GetDocument(); IntPtr hIMC = Win32.ImmGetContext(this.Handle); RenderProfile prof = GetRenderProfile(); //�t�H���g�̃Z�b�g�͂P����悢�̂��H Win32.LOGFONT lf = new Win32.LOGFONT(); prof.CalcFont(null, CharGroup.CJKZenkaku).ToLogFont(lf); Win32.ImmSetCompositionFont(hIMC, lf); Win32.COMPOSITIONFORM form = new Win32.COMPOSITIONFORM(); form.dwStyle = Win32.CFS_POINT; Win32.SystemMetrics sm = GEnv.SystemMetrics; //Debug.WriteLine(String.Format("{0} {1} {2}", document.CaretColumn, charwidth, document.CurrentLine.CharPosToDisplayPos(document.CaretColumn))); form.ptCurrentPos.x = sm.ControlBorderWidth + (int)(prof.Pitch.Width * (document.CaretColumn)); form.ptCurrentPos.y = sm.ControlBorderHeight + (int)((prof.Pitch.Height + prof.LineSpacing) * (document.CurrentLineNumber - document.TopLineNumber)); bool r = Win32.ImmSetCompositionWindow(hIMC, ref form); Debug.Assert(r); Win32.ImmReleaseContext(this.Handle, hIMC); }
protected override void WndProc(ref Message m) { if (m.Msg == (int)Win32.WMessages.WM_GETDLGCODE) { if (m.WParam == (IntPtr)Win32.VKey.VK_TAB && !owner.AcceptsTab) { return; } if (Toolkit.IsKeyDown(Win32.VKey.VK_MENU)) { return; } m.Result = (IntPtr)(Win32.DLGC.DLGC_WANTMESSAGE | Win32.DLGC.DLGC_HASSETSEL); return; } if (m.Msg == (int)Win32.WMessages.WM_CHAR) { var sheet = owner.currentWorksheet; int inputChar = m.WParam.ToInt32(); if (inputChar != 8 && // backspace inputChar != 13 && // enter inputChar != 27 && // escape inputChar != '\t' // tab ) { inputChar = sheet.RaiseCellEditCharInputed(inputChar); } if (inputChar == (int)Keys.Escape) { sheet.EndEdit(EndEditReason.Cancel); return; } if (inputChar == (int)Keys.Tab) { sheet.EndEdit(EndEditReason.NormalFinish); sheet.OnTabKeyPressed(Toolkit.IsKeyDown(Win32.VKey.VK_SHIFT)); return; } if (inputChar == (int)Keys.Enter) { sheet.EndEdit(EndEditReason.NormalFinish); sheet.OnEnterKeyPressed(Toolkit.IsKeyDown(Win32.VKey.VK_SHIFT)); return; } m.WParam = new IntPtr(inputChar); base.WndProc(ref m); return; } else if (m.Msg == (int)Win32.WMessages.WM_IME_STARTCOMPOSITION) { CheckAndUpdateWidth(); } else if (m.Msg == (int)Win32.WMessages.WM_IME_COMPOSITION) { IntPtr ime = Win32.ImmGetContext(this.Handle); int strLen = Win32.ImmGetCompositionString(ime, (int)Win32.GCS.GCS_COMPREADATTR, null, 0); StringBuilder sb = new StringBuilder(strLen); Win32.ImmGetCompositionString(ime, (int)Win32.GCS.GCS_COMPREADATTR, sb, strLen); Win32.COMPOSITIONFORM com = new Win32.COMPOSITIONFORM(); Win32.ImmGetCompositionWindow(ime, ref com); com.rcArea = new System.Drawing.Rectangle(0, 0, 300, Height); bool b = Win32.ImmSetCompositionWindow(ime, ref com); Win32.ImmReleaseContext(this.Handle, ime); } base.WndProc(ref m); }