Ejemplo n.º 1
0
        /// <summary>
        // Construct a TextCompositionEventArgs with composition infos.
        /// </summary>
        public IMETextCompositionEventArgs(IMEString compositionText,
                                           int cursorPosition,
                                           IMEString[] candidateList = null,
                                           int candidatePageStart    = 0,
                                           int candidatePageSize     = 0,
                                           int candidateSelection    = 0)
        {
            CompositionText = compositionText;
            CursorPosition  = cursorPosition;

            CandidateList      = candidateList;
            CandidatePageStart = candidatePageStart;
            CandidatePageSize  = candidatePageSize;
            CandidateSelection = candidateSelection;
        }
Ejemplo n.º 2
0
        // On text composition update.
        internal static void OnTextComposition(object sender, IMEString compositionText, int cursorPos)
        {
            if (compositionText.Count == 0) // Crash guard
            {
                cursorPos = 0;
            }

            if (cursorPos > compositionText.Count)  // Another crash guard
            {
                cursorPos = compositionText.Count;
            }

            if (TextComposition != null)
            {
                TextComposition.Invoke(sender,
                                       new IMETextCompositionEventArgs(compositionText, cursorPos, CandidateList, CandidatePageStart, CandidatePageSize, CandidateSelection));
            }

            if (TextCompositionCallback != null)
            {
                TextCompositionCallback(compositionText, cursorPos, CandidateList, CandidatePageStart, CandidatePageSize, CandidateSelection);
            }
        }
Ejemplo n.º 3
0
        private void UpdateCandidates()
        {
            uint length = NativeMethods.ImmGetCandidateList(DefaultImc, 0, IntPtr.Zero, 0);

            if (length > 0)
            {
                IntPtr pointer = Marshal.AllocHGlobal((int)length);
                length = NativeMethods.ImmGetCandidateList(DefaultImc, 0, pointer, length);
                NativeMethods.CANDIDATELIST cList = Marshal.PtrToStructure <NativeMethods.CANDIDATELIST>(pointer);

                var selection = (int)cList.dwSelection;
                var pageStart = (int)cList.dwPageStart;
                var pageSize  = (int)cList.dwPageSize;

                IMEString[] candidates = ArrayPool <IMEString> .Shared.Rent(pageSize);

                int i, j;
                for (i = pageStart, j = 0; i < cList.dwCount && j < pageSize; i++, j++)
                {
                    int sOffset = Marshal.ReadInt32(pointer, 24 + 4 * i);
                    candidates[j] = new IMEString(pointer + sOffset);
                }

                //Debug.WriteLine("IMM========IMM");
                //Debug.WriteLine("pageStart: {0}, pageSize: {1}, selection: {2}, candidates:", pageStart, pageSize, selection);
                //for (int k = 0; k < candidates.Length; k++)
                //    Debug.WriteLine("  {2}{0}.{1}", k + 1, candidates[k], k == selection ? "*" : "");
                //Debug.WriteLine("IMM++++++++IMM");

                InputMethod.CandidatePageStart = pageStart;
                InputMethod.CandidatePageSize  = pageSize;
                InputMethod.CandidateSelection = selection;
                InputMethod.CandidateList      = candidates;

                Marshal.FreeHGlobal(pointer);
            }
        }
Ejemplo n.º 4
0
        private void OnUIElement(int uiElementId, bool onStart)
        {
            if (InputMethod.ShowOSImeWindow || !_supportUIElement)
            {
                return;
            }

            ITfUIElement uiElement;

            TextServicesContext.Current.UIElementMgr.GetUIElement(uiElementId, out uiElement);

            ITfCandidateListUIElementBehavior candList;

            try
            {
                candList = uiElement.QueryInterface <ITfCandidateListUIElementBehavior>();
            }
            catch (SharpGenException)
            {
                _supportUIElement = false;
                return;
            }
            finally
            {
                uiElement.Dispose();
            }

            uint selection = 0;
            uint currentPage = 0;
            uint count = 0;
            uint pageCount = 0;
            uint pageStart = 0;
            uint pageSize = 0;
            uint i, j;

            candList.GetSelection(out selection);
            candList.GetCurrentPage(out currentPage);

            candList.GetCount(out count);
            // Limit max candidate count to 100, or candList.GetString() would crash.
            // Don't know why???
            if (count > MaxCandidateCount)
            {
                count = MaxCandidateCount;
            }

            candList.GetPageIndex(null, 0, out pageCount);

            if (pageCount > 0)
            {
                uint[] pageStartIndexes = ArrayPool <uint> .Shared.Rent((int)pageCount);

                candList.GetPageIndex(pageStartIndexes, pageCount, out pageCount);
                pageStart = pageStartIndexes[currentPage];

                if (pageStart >= count - 1)
                {
                    candList.Abort();
                    ArrayPool <uint> .Shared.Return(pageStartIndexes);

                    return;
                }

                if (currentPage < pageCount - 1)
                {
                    pageSize = Math.Min(count, pageStartIndexes[currentPage + 1]) - pageStart;
                }
                else
                {
                    pageSize = count - pageStart;
                }

                ArrayPool <uint> .Shared.Return(pageStartIndexes);
            }

            selection -= pageStart;

            IMEString[] candidates = _IMEStringPool.Rent((int)pageSize);

            IntPtr bStrPtr;

            for (i = pageStart, j = 0; i < count && j < pageSize; i++, j++)
            {
                candList.GetString(i, out bStrPtr);
                candidates[j] = new IMEString(bStrPtr);
            }

            //Debug.WriteLine("TSF========TSF");
            //Debug.WriteLine("pageStart: {0}, pageSize: {1}, selection: {2}, currentPage: {3} candidates:", pageStart, pageSize, selection, currentPage);
            //for (int k = 0; k < candidates.Length; k++)
            //    Debug.WriteLine("  {2}{0}.{1}", k + 1, candidates[k], k == selection ? "*" : "");
            //Debug.WriteLine("TSF++++++++TSF");

            InputMethod.CandidatePageStart = (int)pageStart;
            InputMethod.CandidatePageSize  = (int)pageSize;
            InputMethod.CandidateSelection = (int)selection;
            InputMethod.CandidateList      = candidates;

            if (_currentComposition != null)
            {
                InputMethod.OnTextComposition(this, new IMEString(_currentComposition), _acpEnd);
                _IMEStringPool.Return(candidates);
            }

            candList.Dispose();
        }
Ejemplo n.º 5
0
 public Enumerator(IMEString imeString)
 {
     _imeString        = imeString;
     _currentCharacter = '\0';
     _currentIndex     = -1;
 }