private void IMENotify(int WParam) { switch (WParam) { case IMM.ImnSetOpenStatus: _context = IMM.ImmGetContext(Handle); IsIMEOpen = IMM.ImmGetOpenStatus(_context); System.Diagnostics.Trace.WriteLine(string.Format("IsIMEOpen: {0}", IsIMEOpen ? "True" : "False")); break; case IMM.ImnOpenCandidate: case IMM.ImnChangeCandidate: IMEChangeCandidate(); break; case IMM.ImnCloseCandidate: IMECloseCandidate(); break; case IMM.ImnPrivate: break; default: break; } }
/// <summary> /// Disable the IME /// </summary> public void DisableIME() { IsEnabled = false; IMM.DestroyCaret(); IMM.ImmAssociateContext(Handle, IntPtr.Zero); }
protected override void WndProc(ref Message msg) { switch (msg.Msg) { case IMM.ImeSetContext: if (msg.WParam.ToInt32() == 1) { if (IsEnabled) { EnableIME(); } if (!_showIMEWin) { msg.LParam = (IntPtr)0; } } break; case IMM.InputLanguageChange: return; case IMM.ImeNotify: IMENotify(msg.WParam.ToInt32()); if (!_showIMEWin) { return; } break; case IMM.ImeStartCompostition: IMEStartComposion(msg.LParam.ToInt32()); return; case IMM.ImeComposition: IMESetContextForAll(); IMEComposition(msg.LParam.ToInt32()); IMM.ImmReleaseContext(Handle, _context); break; case IMM.ImeEndComposition: IMESetContextForAll(); IMEEndComposition(msg.LParam.ToInt32()); IMM.ImmReleaseContext(Handle, _context); if (!_showIMEWin) { return; } break; case IMM.Char: CharEvent(msg.WParam.ToInt32()); break; } base.WndProc(ref msg); }
public void SetTextInputRect(ref Rectangle rect) { _context = IMM.ImmGetContext(Handle); var candidateForm = new IMM.CandidateForm(new IMM.Point(rect.X, rect.Y)); IMM.ImmSetCandidateWindow(_context, ref candidateForm); IMM.SetCaretPos(rect.X, rect.Y); IMM.ImmReleaseContext(Handle, _context); }
private void IMESetContextForAll() { _context = IMM.ImmGetContext(Handle); _compcurpos.IMEHandle = _context; _compstr.IMEHandle = _context; _compclause.IMEHandle = _context; _compattr.IMEHandle = _context; _compread.IMEHandle = _context; _compreadclause.IMEHandle = _context; _compreadattr.IMEHandle = _context; _resstr.IMEHandle = _context; _resclause.IMEHandle = _context; _resread.IMEHandle = _context; _resreadclause.IMEHandle = _context; }
internal override void Update() { Length = IMM.ImmGetCompositionString(IMEHandle, Flag, IntPtr.Zero, 0); IntPtr pointer = Marshal.AllocHGlobal(Length); try { IMM.ImmGetCompositionString(IMEHandle, Flag, pointer, Length); _values = new byte[Length]; Marshal.Copy(pointer, _values, 0, Length); } finally { Marshal.FreeHGlobal(pointer); } }
private void CharEvent(int wParam) { var charInput = (char)wParam; var key = Microsoft.Xna.Framework.Input.Keys.None; if (!char.IsSurrogate(charInput)) { key = (Microsoft.Xna.Framework.Input.Keys)(IMM.VkKeyScanEx(charInput, InputLanguage.CurrentInputLanguage.Handle) & 0xff); } _imeHandler.OnTextInput(charInput, key); if (IsEnabled) { IMECloseCandidate(); } }
/// <summary> /// Enable the IME /// </summary> public void EnableIME() { IsEnabled = true; IMM.DestroyCaret(); IMM.CreateCaret(Handle, IntPtr.Zero, 1, 1); _context = IMM.ImmGetContext(Handle); if (_context != IntPtr.Zero) { IMM.ImmAssociateContext(Handle, _context); IMM.ImmReleaseContext(Handle, _context); return; } // This fix the bug that _context is 0 on fullscreen mode. ImeContext.Enable(Handle); }
private void IMEChangeCandidate() { _context = IMM.ImmGetContext(Handle); uint length = IMM.ImmGetCandidateList(_context, 0, IntPtr.Zero, 0); if (length > 0) { IntPtr pointer = Marshal.AllocHGlobal((int)length); length = IMM.ImmGetCandidateList(_context, 0, pointer, length); IMM.CandidateList cList = (IMM.CandidateList)Marshal.PtrToStructure(pointer, typeof(IMM.CandidateList)); CandidatesSelection = cList.dwSelection; CandidatesPageStart = cList.dwPageStart; CandidatesPageSize = cList.dwPageSize; if (cList.dwCount > 1) { Candidates = new string[cList.dwCount]; for (int i = 0; i < cList.dwCount; i++) { int sOffset = Marshal.ReadInt32(pointer, 24 + 4 * i); Candidates[i] = Marshal.PtrToStringUni(pointer + sOffset); } _imeHandler.OnTextComposition(CompositionString, CompositionCursorPos, new CandidateList { Candidates = Candidates, CandidatesPageStart = CandidatesPageStart, CandidatesPageSize = CandidatesPageSize, CandidatesSelection = CandidatesSelection }); } else { IMECloseCandidate(); } Marshal.FreeHGlobal(pointer); } IMM.ImmReleaseContext(Handle, _context); }
internal override void Update() { Value = IMM.ImmGetCompositionString(IMEHandle, Flag, IntPtr.Zero, 0); }