Esempio n. 1
0
        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);
        }
Esempio n. 2
0
        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);
        }
Esempio n. 3
0
        /// <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);
        }
Esempio n. 4
0
        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);
        }