public TextCaret(IWpfTextView textView, IAdornmentLayer caretLayer, ISmartIndentationService smartIndentationService, IClassificationFormatMap classificationFormatMap) { if (caretLayer == null) { throw new ArgumentNullException(nameof(caretLayer)); } if (classificationFormatMap == null) { throw new ArgumentNullException(nameof(classificationFormatMap)); } this.textView = textView ?? throw new ArgumentNullException(nameof(textView)); imeState = new ImeState(); this.smartIndentationService = smartIndentationService ?? throw new ArgumentNullException(nameof(smartIndentationService)); preferredXCoordinate = 0; __preferredYCoordinate = 0; Affinity = PositionAffinity.Successor; currentPosition = new VirtualSnapshotPoint(textView.TextSnapshot, 0); textView.TextBuffer.ChangedHighPriority += TextBuffer_ChangedHighPriority; textView.TextBuffer.ContentTypeChanged += TextBuffer_ContentTypeChanged; textView.Options.OptionChanged += Options_OptionChanged; textView.VisualElement.AddHandler(UIElement.GotKeyboardFocusEvent, new KeyboardFocusChangedEventHandler(VisualElement_GotKeyboardFocus), true); textView.VisualElement.AddHandler(UIElement.LostKeyboardFocusEvent, new KeyboardFocusChangedEventHandler(VisualElement_LostKeyboardFocus), true); textView.LayoutChanged += TextView_LayoutChanged; textCaretLayer = new TextCaretLayer(this, caretLayer, classificationFormatMap); InputMethod.SetIsInputMethodSuspended(textView.VisualElement, true); }
void InitializeIME() { if (imeState.HwndSource != null) { return; } imeState.HwndSource = PresentationSource.FromVisual(textView.VisualElement) as HwndSource; if (imeState.HwndSource == null) { return; } Debug.Assert(imeState.Context == IntPtr.Zero); Debug.Assert(imeState.HWND == IntPtr.Zero); Debug.Assert(imeState.OldContext == IntPtr.Zero); if (textView.Options.DoesViewProhibitUserInput()) { imeState.Context = IntPtr.Zero; imeState.HWND = IntPtr.Zero; } else { imeState.HWND = ImeState.ImmGetDefaultIMEWnd(IntPtr.Zero); imeState.Context = ImeState.ImmGetContext(imeState.HWND); } imeState.OldContext = ImeState.ImmAssociateContext(imeState.HwndSource.Handle, imeState.Context); imeState.HwndSource.AddHook(WndProc); TfThreadMgrHelper.SetFocus(); }
public HexCaretImpl(WpfHexView hexView, HexAdornmentLayer caretLayer, VSTC.IClassificationFormatMap classificationFormatMap, VSTC.IClassificationTypeRegistryService classificationTypeRegistryService) { if (hexView == null) { throw new ArgumentNullException(nameof(hexView)); } if (caretLayer == null) { throw new ArgumentNullException(nameof(caretLayer)); } if (classificationFormatMap == null) { throw new ArgumentNullException(nameof(classificationFormatMap)); } if (classificationTypeRegistryService == null) { throw new ArgumentNullException(nameof(classificationTypeRegistryService)); } this.hexView = hexView; imeState = new ImeState(); preferredXCoordinate = 0; __preferredYCoordinate = 0; hexView.Options.OptionChanged += Options_OptionChanged; hexView.VisualElement.AddHandler(UIElement.GotKeyboardFocusEvent, new KeyboardFocusChangedEventHandler(VisualElement_GotKeyboardFocus), true); hexView.VisualElement.AddHandler(UIElement.LostKeyboardFocusEvent, new KeyboardFocusChangedEventHandler(VisualElement_LostKeyboardFocus), true); hexView.LayoutChanged += HexView_LayoutChanged; hexView.BufferLinesChanged += HexView_BufferLinesChanged; hexView.ZoomLevelChanged += HexView_ZoomLevelChanged; hexCaretLayer = new HexCaretLayer(this, caretLayer, classificationFormatMap, classificationTypeRegistryService); InputMethod.SetIsInputMethodSuspended(hexView.VisualElement, true); }
public TextCaret(IWpfTextView textView, IAdornmentLayer caretLayer, ISmartIndentationService smartIndentationService, IClassificationFormatMap classificationFormatMap) { if (textView == null) throw new ArgumentNullException(nameof(textView)); if (caretLayer == null) throw new ArgumentNullException(nameof(caretLayer)); if (smartIndentationService == null) throw new ArgumentNullException(nameof(smartIndentationService)); if (classificationFormatMap == null) throw new ArgumentNullException(nameof(classificationFormatMap)); this.textView = textView; imeState = new ImeState(); this.smartIndentationService = smartIndentationService; preferredXCoordinate = 0; __preferredYCoordinate = 0; Affinity = PositionAffinity.Successor; currentPosition = new VirtualSnapshotPoint(textView.TextSnapshot, 0); textView.TextBuffer.ChangedHighPriority += TextBuffer_ChangedHighPriority; textView.TextBuffer.ContentTypeChanged += TextBuffer_ContentTypeChanged; textView.Options.OptionChanged += Options_OptionChanged; textView.VisualElement.AddHandler(UIElement.GotKeyboardFocusEvent, new KeyboardFocusChangedEventHandler(VisualElement_GotKeyboardFocus), true); textView.VisualElement.AddHandler(UIElement.LostKeyboardFocusEvent, new KeyboardFocusChangedEventHandler(VisualElement_LostKeyboardFocus), true); textView.LayoutChanged += TextView_LayoutChanged; textCaretLayer = new TextCaretLayer(this, caretLayer, classificationFormatMap); InputMethod.SetIsInputMethodSuspended(textView.VisualElement, true); }
void MoveImeCompositionWindow() { if (!IsValuesCaretPresent && !IsAsciiCaretPresent) { return; } if (imeState.Context == IntPtr.Zero) { return; } var line = ContainingHexViewLine; if (line.VisibilityState == VSTF.VisibilityState.Unattached) { return; } var linePos = GetLinePosition(line.BufferLine, currentPosition); if (linePos == null) { return; } var charBounds = line.GetExtendedCharacterBounds(linePos.Value); const int CFS_DEFAULT = 0x0000; const int CFS_FORCE_POSITION = 0x0020; var compForm = new ImeState.COMPOSITIONFORM(); compForm.dwStyle = CFS_DEFAULT; var rootVisual = imeState.HwndSource.RootVisual; GeneralTransform generalTransform = null; if (rootVisual != null && rootVisual.IsAncestorOf(hexView.VisualElement)) { generalTransform = hexView.VisualElement.TransformToAncestor(rootVisual); } var compTarget = imeState.HwndSource.CompositionTarget; if (generalTransform != null && compTarget != null) { var transform = compTarget.TransformToDevice; compForm.dwStyle = CFS_FORCE_POSITION; var caretPoint = transform.Transform(generalTransform.Transform(new Point(charBounds.Left - hexView.ViewportLeft, charBounds.TextTop - hexView.ViewportTop))); var viewPointTop = transform.Transform(generalTransform.Transform(new Point(0, 0))); var viewPointBottom = transform.Transform(generalTransform.Transform(new Point(hexView.ViewportWidth, hexView.ViewportHeight))); compForm.ptCurrentPos = new ImeState.POINT(Math.Max(0, (int)caretPoint.X), Math.Max(0, (int)caretPoint.Y)); compForm.rcArea = new ImeState.RECT( Math.Max(0, (int)viewPointTop.X), Math.Max(0, (int)viewPointTop.Y), Math.Max(0, (int)viewPointBottom.X), Math.Max(0, (int)viewPointBottom.Y)); } ImeState.ImmSetCompositionWindow(imeState.Context, ref compForm); }
void CancelCompositionString() { if (imeState.Context == IntPtr.Zero) { return; } const int NI_COMPOSITIONSTR = 0x0015; const int CPS_CANCEL = 0x0004; ImeState.ImmNotifyIME(imeState.Context, NI_COMPOSITIONSTR, CPS_CANCEL, 0); }
void StopIME(bool cancelCompositionString) { if (imeState.HwndSource == null) { return; } if (cancelCompositionString) { CancelCompositionString(); } ImeState.ImmAssociateContext(imeState.HwndSource.Handle, imeState.OldContext); ImeState.ImmReleaseContext(imeState.HWND, imeState.Context); imeState.HwndSource.RemoveHook(WndProc); imeState.Clear(); textCaretLayer.SetImeStarted(false); }
protected override void WndProc(ref Message m) { if (m.Msg == WM_KEYDOWN) { if (m.LParam.ToInt32() == 917505) { _BackSpaceKeyPressed = true; } else { _BackSpaceKeyPressed = false; } } if (m.Msg == WM_IME_COMPOSITION || m.Msg == WM_IME_STARTCOMPOSITION || m.Msg == WM_IME_ENDCOMPOSITION) { _ImeState = ImeState.None; } if (m.Msg == WM_IME_ENDCOMPOSITION) { OnTextChanged(EventArgs.Empty); } if (m.Msg == WM_IME_COMPOSITION) { int comp = m.LParam.ToInt32(); if ((comp & GCS_RESULTSTR) > 0) { _ImeState = ImeState.Complete; } else if ((comp & GCS_COMPSTR) > 0) { _ImeState = ImeState.Compounding; OnTextChanged(EventArgs.Empty); } } base.WndProc(ref m); }