private void IMEEndComposition(int lParam) { InputMethod.ClearCandidates(); ClearComposition(); InputMethod.OnTextCompositionEnded(this); }
private static IntPtr WndProc(IntPtr hWnd, uint msg, IntPtr wParam, IntPtr lParam) { if (Imm32Manager.ImmEnabled) { if (Imm32Manager.Current.ProcessMessage(hWnd, msg, ref wParam, ref lParam)) { return(IntPtr.Zero); } } switch (msg) { case NativeMethods.WM_DESTROY: TextServicesContext.Current.Uninitialize(true); break; case NativeMethods.WM_CHAR: { if (InputMethod.Enabled) { InputMethod.OnTextInput(null, (char)wParam.ToInt32()); } break; } } return(NativeMethods.CallWindowProc(_prevWndProc, hWnd, msg, wParam, lParam)); }
private void IMEComposition(int lParam) { if (_compositionStringHandler.Update(lParam)) { _compositionCursorHandler.Update(); InputMethod.OnTextComposition(this, new IMEString(_compositionStringHandler.Values, _compositionStringHandler.Count), _compositionCursorHandler.Value); } }
//------------------------------------------------------ // // Public Methods - ITfContextOwnerCompositionSink // //------------------------------------------------------ #region ITfContextOwnerCompositionSink public void OnStartComposition(ITfCompositionView view, out bool ok) { // Return true in ok to start the composition. ok = true; _compositionStart = _compositionLength = 0; _currentComposition.Clear(); InputMethod.OnTextCompositionStarted(this); _compViews.Add(view); }
public void OnEndEdit(ITfContext context, int ecReadOnly, ITfEditRecord editRecord) { ITfProperty property; context.GetProperty(GUID_PROP_COMPOSING, out property); ITfRangeACP rangeACP; TextServicesContext.Current.ContextOwnerServices.CreateRange(_compositionStart, _compositionStart + _compositionLength, out rangeACP); Variant val; property.GetValue(ecReadOnly, rangeACP, out val); property.Dispose(); rangeACP.Dispose(); if (val.Value == null || (int)val.Value == 0) { if (_commitLength == 0 || _inputBuffer.Count == 0) { return; } //Debug.WriteLine("Composition result: {0}", new object[] { new string(_inputBuffer.GetRange(_commitStart, _commitLength).ToArray()) }); _commited = true; for (int i = _commitStart; i < _commitLength; i++) { InputMethod.OnTextInput(this, _inputBuffer[i]); } } if (_commited) { return; } if (_inputBuffer.Count == 0 && _compositionLength > 0) // Composition just ended { return; } _currentComposition.Clear(); for (int i = _compositionStart; i < _compositionLength; i++) { _currentComposition.Add(_inputBuffer[i]); } InputMethod.OnTextComposition(this, new IMEString(_currentComposition), _acpEnd); //var compStr = new string(_currentComposition.ToArray()); //compStr = compStr.Insert(_acpEnd, "|"); //Debug.WriteLine("Composition string: {0}, cursor pos: {1}", compStr, _acpEnd); }
private void IMENotify(int WParam) { switch (WParam) { case NativeMethods.IMN_OPENCANDIDATE: case NativeMethods.IMN_CHANGECANDIDATE: IMEChangeCandidate(); break; case NativeMethods.IMN_CLOSECANDIDATE: InputMethod.ClearCandidates(); break; default: break; } }
private void IMEChangeCandidate() { if (TextServicesLoader.ServicesInstalled) // TSF is enabled { if (!TextStore.Current.SupportUIElement) // But active IME not support UIElement { UpdateCandidates(); // We have to fetch candidate list here. } return; } // Normal candidate list fetch in IMM32 UpdateCandidates(); // Send event on candidate updates InputMethod.OnTextComposition(this, new IMEString(_compositionStringHandler.Values, _compositionStringHandler.Count), _compositionCursorHandler.Value); if (InputMethod.CandidateList != null) { ArrayPool <IMEString> .Shared.Return(InputMethod.CandidateList); } }
public void OnEndComposition(ITfCompositionView view) { var range = view.Range; var rangeacp = range.QueryInterface <ITfRangeACP>(); rangeacp.GetExtent(out _commitStart, out _commitLength); rangeacp.Dispose(); range.Dispose(); // Ensure composition string reset _compositionStart = _compositionLength = 0; _currentComposition.Clear(); InputMethod.ClearCandidates(); InputMethod.OnTextCompositionEnded(this); view.Dispose(); foreach (var item in _compViews) { item.Dispose(); } _compViews.Clear(); }
private void IMEStartComposion(int lParam) { InputMethod.OnTextCompositionStarted(this); ClearComposition(); }
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(); }