Example #1
0
        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;
            }
        }
Example #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);
        }
Example #3
0
        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;
        }
Example #4
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);
        }
Example #5
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);
        }