private void IMESetContext(ref Message msg)
        {
            if (msg.WParam.ToInt32() == 1)
            {
                IntPtr ptr = IMM.ImmGetContext(Handle);
                if (_context == IntPtr.Zero)
                {
                    _context = ptr;
                }
                else if (ptr == IntPtr.Zero && IsEnabled)
                {
                    EnableIME();
                }

                _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;

                if (!_showIMEWin)
                {
                    msg.LParam = (IntPtr)0;
                }
            }
        }
        /// <summary>
        /// Disable the IME
        /// </summary>
        public void DisableIME()
        {
            IsEnabled = false;

            IMM.ImmAssociateContext(Handle, IntPtr.Zero);
            IMM.ImmReleaseContext(Handle, _context);
        }
        /// <summary>
        /// Enable the IME
        /// </summary>
        public void EnableIME()
        {
            IsEnabled = true;

            if (_context != IntPtr.Zero)
            {
                IMM.ImmAssociateContext(Handle, _context);
                return;
            }

            // This fix the bug that _context is 0 on fullscreen mode.
            ImeContext.Enable(Handle);
        }
        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);
            }
        }
Example #5
0
 /// <summary>
 /// Constructor, must be called when the window create.
 /// </summary>
 /// <param name="handle">Handle of the window</param>
 /// <param name="showDefaultIMEWindow">True if you want to display the default IME window</param>
 public IMENativeWindow(IntPtr handle, bool showDefaultIMEWindow = false)
 {
     this._context        = _context = IMM.ImmCreateContext();
     this.Candidates      = new string[0];
     this._compcurpos     = new IMMCompositionInt(IMM.GCSCursorPos, _context);
     this._compstr        = new IMMCompositionString(IMM.GCSCompStr, _context);
     this._compclause     = new IMMCompositionString(IMM.GCSCompClause, _context);
     this._compattr       = new IMMCompositionString(IMM.GCSCompAttr, _context);
     this._compread       = new IMMCompositionString(IMM.GCSCompReadStr, _context);
     this._compreadclause = new IMMCompositionString(IMM.GCSCompReadClause, _context);
     this._compreadattr   = new IMMCompositionString(IMM.GCSCompReadAttr, _context);
     this._resstr         = new IMMCompositionString(IMM.GCSResultStr, _context);
     this._resclause      = new IMMCompositionString(IMM.GCSResultClause, _context);
     this._resread        = new IMMCompositionString(IMM.GCSResultReadStr, _context);
     this._resreadclause  = new IMMCompositionString(IMM.GCSResultReadClause, _context);
     this._showIMEWin     = showDefaultIMEWindow;
     AssignHandle(handle);
 }
Example #6
0
        private void IMEChangeCandidate()
        {
            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);
                        if (IntPtr.Size == 4)
                        {
                            Candidates[i] = Marshal.PtrToStringUni((IntPtr)(pointer.ToInt32() + sOffset));
                        }
                        else
                        {
                            Candidates[i] = Marshal.PtrToStringUni((IntPtr)(pointer.ToInt64() + sOffset));
                        }
                    }

                    if (CandidatesReceived != null)
                    {
                        CandidatesReceived(this, EventArgs.Empty);
                    }
                }
                else
                {
                    IMECloseCandidate();
                }

                Marshal.FreeHGlobal(pointer);
            }
        }
 internal override void Update()
 {
     Value = IMM.ImmGetCompositionString(IMEHandle, Flag, IntPtr.Zero, 0);
 }
Example #8
0
        /// <summary>
        /// Enable the IME
        /// </summary>
        public void EnableIME()
        {
            IsEnabled = true;

            IMM.ImmAssociateContext(Handle, _context);
        }