internal static void NotifyCharactersRemoved(TextSurfaceEventListener listener, TextDomEventArgs e) { if (listener.CharacterRemoved != null) { listener.CharacterRemoved(listener, e); } }
internal static void NotifyCharactersReplaced(TextSurfaceEventListener listener, char c) { if (listener.CharacterReplaced != null) { listener.CharacterReplaced(listener, new TextDomEventArgs(c)); } }
internal static void NotifyKeyDown(TextSurfaceEventListener listener, UIKeys key) { if (listener.KeyDown != null) { listener.KeyDown(listener, new TextDomEventArgs(key)); } }
internal static void NofitySplitNewLine(TextSurfaceEventListener listener, UIKeyEventArgs e) { if (listener.SplitedNewLine != null) { listener.SplitedNewLine(listener, e); } }
internal static void NotifyReplaceAll(TextSurfaceEventListener listener, TextDomEventArgs e) { if (listener.ReplacedAll != null) { listener.ReplacedAll(listener, e); } }
internal static void NotifyArrowKeyCaretPosChanged(TextSurfaceEventListener listener, UIKeys key) { if (listener.ArrowKeyCaretPosChanged != null) { listener.ArrowKeyCaretPosChanged(listener, new TextDomEventArgs(key)); } }
internal static bool NotifyPreviewBackSpace(TextSurfaceEventListener listener) { if (listener.PreviewBackSpaceKeyDown != null) { TextDomEventArgs e = new TextDomEventArgs(UIKeys.Back); listener.PreviewBackSpaceKeyDown(listener, e); return(e.PreventDefault); } return(false); }
internal static bool NotifyPreviewBackSpace(TextSurfaceEventListener listener) { if (listener.PreviewBackSpaceKeyDown != null) { TextDomEventArgs e = new TextDomEventArgs(UIKeys.Back); listener.PreviewBackSpaceKeyDown(listener, e); return e.PreventDefault; } return false; }
internal static bool NotifyPreviewArrow(TextSurfaceEventListener listener, UIKeys key) { if (listener.PreviewArrowKeyDown != null) { TextDomEventArgs e = new TextDomEventArgs(key); listener.PreviewArrowKeyDown(listener, e); return(e.PreventDefault); } return(false); }
public void OnKeyPress(UIKeyEventArgs e) { this.SetCaretState(true); //------------------------ if (e.IsControlCharacter) { OnKeyDown(e); return; } char c = e.KeyChar; e.CancelBubbling = true; if (internalTextLayerController.SelectionRange != null && internalTextLayerController.SelectionRange.IsValid) { InvalidateGraphicLocalArea(this, GetSelectionUpdateArea()); } bool preventDefault = false; if (textSurfaceEventListener != null && !(preventDefault = TextSurfaceEventListener.NotifyPreviewKeydown(textSurfaceEventListener, c))) { internalTextLayerController.UpdateSelectionRange(); } if (preventDefault) { return; } if (internalTextLayerController.SelectionRange != null) { internalTextLayerController.AddCharToCurrentLine(c); if (textSurfaceEventListener != null) { TextSurfaceEventListener.NotifyCharactersReplaced(textSurfaceEventListener, e.KeyChar); } } else { internalTextLayerController.AddCharToCurrentLine(c); if (textSurfaceEventListener != null) { TextSurfaceEventListener.NotifyCharacterAdded(textSurfaceEventListener, e.KeyChar); } } EnsureCaretVisible(); if (textSurfaceEventListener != null) { TextSurfaceEventListener.NotifyKeyDown(textSurfaceEventListener, e.KeyCode); } }
internal static bool NotifyPreviewKeydown(TextSurfaceEventListener listener, char c) { if (listener.IsRegisterPreviewKeyDownChar(c)) { if (listener.PreviewRegisteredKeyDown != null) { TextDomEventArgs e = new TextDomEventArgs(c); listener.PreviewRegisteredKeyDown(listener, e); return(e.PreventDefault); } } return(false); }
public void DoTab() { if (internalTextLayerController.SelectionRange != null) { InvalidateGraphicLocalArea(this, GetSelectionUpdateArea()); } internalTextLayerController.AddCharToCurrentLine(' '); internalTextLayerController.AddCharToCurrentLine(' '); internalTextLayerController.AddCharToCurrentLine(' '); internalTextLayerController.AddCharToCurrentLine(' '); internalTextLayerController.AddCharToCurrentLine(' '); if (textSurfaceEventListener != null) { TextSurfaceEventListener.NotifyCharacterAdded(textSurfaceEventListener, '\t'); } InvalidateGraphicOfCurrentLineArea(); }
public void OnKeyDown(UIKeyEventArgs e) { this.SetCaretState(true); if (!e.HasKeyData) { return; } switch (e.KeyCode) { case UIKeys.Home: { this.DoHome(e.Shift); } break; case UIKeys.End: { this.DoEnd(e.Shift); } break; case UIKeys.Back: { if (internalTextLayerController.SelectionRange != null) { InvalidateGraphicLocalArea(this, GetSelectionUpdateArea()); } else { InvalidateGraphicOfCurrentLineArea(); } if (textSurfaceEventListener == null) { internalTextLayerController.DoBackspace(); } else { if (!TextSurfaceEventListener.NotifyPreviewBackSpace(textSurfaceEventListener) && internalTextLayerController.DoBackspace()) { TextSurfaceEventListener.NotifyCharactersRemoved(textSurfaceEventListener, new TextDomEventArgs(internalTextLayerController.updateJustCurrentLine)); } } EnsureCaretVisible(); } break; case UIKeys.Delete: { if (internalTextLayerController.SelectionRange != null) { InvalidateGraphicLocalArea(this, GetSelectionUpdateArea()); } else { InvalidateGraphicOfCurrentLineArea(); } if (textSurfaceEventListener == null) { internalTextLayerController.DoDelete(); } else { VisualSelectionRangeSnapShot delpart = internalTextLayerController.DoDelete(); TextSurfaceEventListener.NotifyCharactersRemoved(textSurfaceEventListener, new TextDomEventArgs(internalTextLayerController.updateJustCurrentLine)); } EnsureCaretVisible(); } break; default: { if (textSurfaceEventListener != null) { UIKeys keycode = e.KeyCode; if (keycode >= UIKeys.F1 && keycode <= UIKeys.F12) { InvalidateGraphicLocalArea(this, GetSelectionUpdateArea()); TextSurfaceEventListener.NotifyFunctionKeyDown(textSurfaceEventListener, keycode); EnsureCaretVisible(); } } } break; } if (e.HasKeyData && e.Ctrl) { switch (e.KeyCode) { case UIKeys.C: { StringBuilder stBuilder = GetFreeStringBuilder(); internalTextLayerController.CopySelectedTextToPlainText(stBuilder); if (stBuilder != null) { if (stBuilder.Length == 0) { Clipboard.Clear(); } else { Clipboard.SetText(stBuilder.ToString()); } } ReleaseStringBuilder(stBuilder); } break; case UIKeys.V: { if (Clipboard.ContainUnicodeText()) { internalTextLayerController.AddTextRunsToCurrentLine( new EditableRun[] { new EditableTextRun(this.Root, Clipboard.GetUnicodeText(), this.CurrentTextSpanStyle) }); EnsureCaretVisible(); } } break; case UIKeys.X: { if (internalTextLayerController.SelectionRange != null) { if (internalTextLayerController.SelectionRange != null) { InvalidateGraphicLocalArea(this, GetSelectionUpdateArea()); } StringBuilder stBuilder = GetFreeStringBuilder(); internalTextLayerController.CopySelectedTextToPlainText(stBuilder); if (stBuilder != null) { Clipboard.SetText(stBuilder.ToString()); } internalTextLayerController.DoDelete(); EnsureCaretVisible(); ReleaseStringBuilder(stBuilder); } } break; case UIKeys.Z: { internalTextLayerController.UndoLastAction(); EnsureCaretVisible(); } break; case UIKeys.Y: { internalTextLayerController.ReverseLastUndoAction(); EnsureCaretVisible(); } break; case UIKeys.B: { //TextSpanStyle style = internalTextLayerController.GetFirstTextStyleInSelectedRange(); //TextSpanStyle textStyle = null; ////test only *** ////TODO: make this more configurable //if (style != null) //{ // TextSpanStyle defaultBeh = ((TextSpanStyle)style); // if (defaultBeh.FontBold) // { // textStyle = StyleHelper.CreateNewStyle(Color.Black); // } // else // { // textStyle = StyleHelper.CreateNewStyle(Color.Blue); // } //} //else //{ // textStyle = StyleHelper.CreateNewStyle(Color.Blue); //} //internalTextLayerController.DoFormatSelection(textStyle); //if (internalTextLayerController.updateJustCurrentLine) //{ // InvalidateGraphicOfCurrentLineArea(); //} //else //{ // InvalidateGraphics(); //} } break; } } if (textSurfaceEventListener != null) { TextSurfaceEventListener.NotifyKeyDown(textSurfaceEventListener, e.KeyCode); } }
public bool OnProcessDialogKey(UIKeyEventArgs e) { UIKeys keyData = (UIKeys)e.KeyData; SetCaretState(true); if (isInVerticalPhase && (keyData != UIKeys.Up || keyData != UIKeys.Down)) { isInVerticalPhase = false; } switch (e.KeyCode) { case UIKeys.Home: { OnKeyDown(e); return(true); } case UIKeys.Return: { if (textSurfaceEventListener != null && TextSurfaceEventListener.NotifyPreviewEnter(textSurfaceEventListener)) { return(true); } if (isMultiLine) { if (internalTextLayerController.SelectionRange != null) { InvalidateGraphicLocalArea(this, GetSelectionUpdateArea()); } internalTextLayerController.SplitCurrentLineIntoNewLine(); if (textSurfaceEventListener != null) { TextSurfaceEventListener.NofitySplitNewLine(textSurfaceEventListener, e); } Rectangle lineArea = internalTextLayerController.CurrentLineArea; if (lineArea.Bottom > this.ViewportBottom) { ScrollBy(0, lineArea.Bottom - this.ViewportBottom); } else { InvalidateGraphicOfCurrentLineArea(); } EnsureCaretVisible(); return(true); } return(true); } case UIKeys.Left: { if (textSurfaceEventListener != null && TextSurfaceEventListener.NotifyPreviewArrow(textSurfaceEventListener, keyData)) { return(true); } InvalidateGraphicOfCurrentLineArea(); if (!e.Shift) { internalTextLayerController.CancelSelect(); } else { internalTextLayerController.StartSelectIfNoSelection(); } Point currentCaretPos = Point.Empty; if (!isMultiLine) { while (!internalTextLayerController.IsOnStartOfLine) { Point prvCaretPos = internalTextLayerController.CaretPos; internalTextLayerController.CharIndex--; currentCaretPos = internalTextLayerController.CaretPos; if (currentCaretPos.X != prvCaretPos.X) { break; } } } else { if (internalTextLayerController.IsOnStartOfLine) { internalTextLayerController.CharIndex--; currentCaretPos = internalTextLayerController.CaretPos; } else { while (!internalTextLayerController.IsOnStartOfLine) { Point prvCaretPos = internalTextLayerController.CaretPos; internalTextLayerController.CharIndex--; currentCaretPos = internalTextLayerController.CaretPos; if (currentCaretPos.X != prvCaretPos.X) { break; } } } } //------------------- if (e.Shift) { internalTextLayerController.EndSelectIfNoSelection(); } //------------------- EnsureCaretVisible(); if (textSurfaceEventListener != null) { TextSurfaceEventListener.NotifyArrowKeyCaretPosChanged(textSurfaceEventListener, keyData); } return(true); } case UIKeys.Right: { if (textSurfaceEventListener != null && TextSurfaceEventListener.NotifyPreviewArrow(textSurfaceEventListener, keyData)) { return(true); } InvalidateGraphicOfCurrentLineArea(); if (!e.Shift) { internalTextLayerController.CancelSelect(); } else { internalTextLayerController.StartSelectIfNoSelection(); } Point currentCaretPos = Point.Empty; if (!isMultiLine) { while (!internalTextLayerController.IsOnEndOfLine) { Point prvCaretPos = internalTextLayerController.CaretPos; internalTextLayerController.CharIndex++; currentCaretPos = internalTextLayerController.CaretPos; if (currentCaretPos.X != prvCaretPos.X) { int nextCharWidth = internalTextLayerController.GetNextCharacterWidth(); if (nextCharWidth > 0) { break; } } } } else { if (internalTextLayerController.IsOnEndOfLine) { internalTextLayerController.CharIndex++; currentCaretPos = internalTextLayerController.CaretPos; } else { while (!internalTextLayerController.IsOnEndOfLine) { Point prvCaretPos = internalTextLayerController.CaretPos; internalTextLayerController.CharIndex++; currentCaretPos = internalTextLayerController.CaretPos; if (currentCaretPos.X != prvCaretPos.X) { //forward check next caret int nextCharWidth = internalTextLayerController.GetNextCharacterWidth(); if (nextCharWidth > 0) { break; } } } } } //------------------- if (e.Shift) { internalTextLayerController.EndSelectIfNoSelection(); } //------------------- EnsureCaretVisible(); if (textSurfaceEventListener != null) { TextSurfaceEventListener.NotifyArrowKeyCaretPosChanged(textSurfaceEventListener, keyData); } return(true); } case UIKeys.Down: { if (textSurfaceEventListener != null && TextSurfaceEventListener.NotifyPreviewArrow(textSurfaceEventListener, keyData)) { return(true); } if (isMultiLine) { if (!isInVerticalPhase) { isInVerticalPhase = true; verticalExpectedCharIndex = internalTextLayerController.CharIndex; } //---------------------------- if (!e.Shift) { internalTextLayerController.CancelSelect(); } else { internalTextLayerController.StartSelectIfNoSelection(); } //---------------------------- internalTextLayerController.CurrentLineNumber++; if (verticalExpectedCharIndex > internalTextLayerController.CurrentLineCharCount - 1) { internalTextLayerController.CharIndex = internalTextLayerController.CurrentLineCharCount - 1; } else { internalTextLayerController.CharIndex = verticalExpectedCharIndex; } //---------------------------- if (e.Shift) { internalTextLayerController.EndSelectIfNoSelection(); } //---------------------------- Rectangle lineArea = internalTextLayerController.CurrentLineArea; if (lineArea.Bottom > this.ViewportBottom) { ScrollBy(0, lineArea.Bottom - this.ViewportBottom); } else { InvalidateGraphicOfCurrentLineArea(); } } if (textSurfaceEventListener != null) { TextSurfaceEventListener.NotifyArrowKeyCaretPosChanged(textSurfaceEventListener, keyData); } return(true); } case UIKeys.Up: { if (textSurfaceEventListener != null && TextSurfaceEventListener.NotifyPreviewArrow(textSurfaceEventListener, keyData)) { return(true); } if (isMultiLine) { if (!isInVerticalPhase) { isInVerticalPhase = true; verticalExpectedCharIndex = internalTextLayerController.CharIndex; } //---------------------------- if (!e.Shift) { internalTextLayerController.CancelSelect(); } else { internalTextLayerController.StartSelectIfNoSelection(); } //---------------------------- internalTextLayerController.CurrentLineNumber--; if (verticalExpectedCharIndex > internalTextLayerController.CurrentLineCharCount - 1) { internalTextLayerController.CharIndex = internalTextLayerController.CurrentLineCharCount - 1; } else { internalTextLayerController.CharIndex = verticalExpectedCharIndex; } //---------------------------- if (e.Shift) { internalTextLayerController.EndSelectIfNoSelection(); } Rectangle lineArea = internalTextLayerController.CurrentLineArea; if (lineArea.Top < ViewportY) { ScrollBy(0, lineArea.Top - ViewportY); } else { EnsureCaretVisible(); InvalidateGraphicOfCurrentLineArea(); } } else { } if (textSurfaceEventListener != null) { TextSurfaceEventListener.NotifyArrowKeyCaretPosChanged(textSurfaceEventListener, keyData); } return(true); } case UIKeys.Tab: { DoTab(); return(true); } default: { return(false); } } }
internal static bool NotifyPreviewKeydown(TextSurfaceEventListener listener, char c) { if (listener.IsRegisterPreviewKeyDownChar(c)) { if (listener.PreviewRegisteredKeyDown != null) { TextDomEventArgs e = new TextDomEventArgs(c); listener.PreviewRegisteredKeyDown(listener, e); return e.PreventDefault; } } return false; }
internal static bool NotifyPreviewArrow(TextSurfaceEventListener listener, UIKeys key) { if (listener.PreviewArrowKeyDown != null) { TextDomEventArgs e = new TextDomEventArgs(key); listener.PreviewArrowKeyDown(listener, e); return e.PreventDefault; } return false; }
public void AttachTextDomListener(TextSurfaceEventListener listener) { this.visualTextSurface.TextSurfaceListener = listener; }
internal static void NotifyFunctionKeyDown(TextSurfaceEventListener listener, UIKeys key) { }
public void HandleKeyDown(UIKeyEventArgs e) { this.SetCaretState(true); if (!e.HasKeyData) { return; } switch (e.KeyCode) { case UIKeys.Home: { this.DoHome(e.Shift); } break; case UIKeys.End: { this.DoEnd(e.Shift); } break; case UIKeys.Back: { if (internalTextLayerController.SelectionRange != null) { InvalidateGraphicLocalArea(this, GetSelectionUpdateArea()); } else { InvalidateGraphicOfCurrentLineArea(); } if (textSurfaceEventListener == null) { internalTextLayerController.DoBackspace(); } else { if (!TextSurfaceEventListener.NotifyPreviewBackSpace(textSurfaceEventListener) && internalTextLayerController.DoBackspace()) { TextSurfaceEventListener.NotifyCharactersRemoved(textSurfaceEventListener, new TextDomEventArgs(internalTextLayerController.updateJustCurrentLine)); } } EnsureCaretVisible(); } break; case UIKeys.Delete: { if (internalTextLayerController.SelectionRange != null) { InvalidateGraphicLocalArea(this, GetSelectionUpdateArea()); } else { InvalidateGraphicOfCurrentLineArea(); } if (textSurfaceEventListener == null) { internalTextLayerController.DoDelete(); } else { VisualSelectionRangeSnapShot delpart = internalTextLayerController.DoDelete(); TextSurfaceEventListener.NotifyCharactersRemoved(textSurfaceEventListener, new TextDomEventArgs(internalTextLayerController.updateJustCurrentLine)); } EnsureCaretVisible(); } break; default: { if (textSurfaceEventListener != null) { UIKeys keycode = e.KeyCode; if (keycode >= UIKeys.F1 && keycode <= UIKeys.F12) { InvalidateGraphicLocalArea(this, GetSelectionUpdateArea()); TextSurfaceEventListener.NotifyFunctionKeyDown(textSurfaceEventListener, keycode); EnsureCaretVisible(); } } } break; } if (e.HasKeyData && e.Ctrl) { switch (e.KeyCode) { case UIKeys.A: { //select all //.... this.CurrentLineNumber = 0; //start select to end DoEnd(true); //simulate this.CurrentLineNumber = this.LineCount - 1; DoEnd(true); } break; case UIKeys.C: { StringBuilder stBuilder = GetFreeStringBuilder(); internalTextLayerController.CopySelectedTextToPlainText(stBuilder); if (stBuilder != null) { if (stBuilder.Length == 0) { Clipboard.Clear(); } else { Clipboard.SetText(stBuilder.ToString()); } } ReleaseStringBuilder(stBuilder); } break; case UIKeys.V: { if (Clipboard.ContainUnicodeText()) { //1. we need to parse multi-line to single line //this may need text-break services internalTextLayerController.AddUnformattedStringToCurrentLine( Clipboard.GetUnicodeText(), this.currentSpanStyle); EnsureCaretVisible(); } } break; case UIKeys.X: { if (internalTextLayerController.SelectionRange != null) { if (internalTextLayerController.SelectionRange != null) { InvalidateGraphicLocalArea(this, GetSelectionUpdateArea()); } StringBuilder stBuilder = GetFreeStringBuilder(); internalTextLayerController.CopySelectedTextToPlainText(stBuilder); if (stBuilder != null) { Clipboard.SetText(stBuilder.ToString()); } internalTextLayerController.DoDelete(); EnsureCaretVisible(); ReleaseStringBuilder(stBuilder); } } break; case UIKeys.Z: { internalTextLayerController.UndoLastAction(); EnsureCaretVisible(); } break; case UIKeys.Y: { internalTextLayerController.ReverseLastUndoAction(); EnsureCaretVisible(); } break; case UIKeys.B: { // //test add markers // //if (internalTextLayerController.SelectionRange != null) //{ // // // internalTextLayerController.SelectionRange.SwapIfUnOrder(); // VisualMarkerSelectionRange markerSelRange = // VisualMarkerSelectionRange.CreateFromSelectionRange( // internalTextLayerController.SelectionRange.GetSelectionRangeSnapshot()); // //then add to the marker layers // markerSelRange.BindToTextLayer(textLayer); // internalTextLayerController.VisualMarkers.Add(markerSelRange); //} // //TextSpanStyle style = internalTextLayerController.GetFirstTextStyleInSelectedRange(); //TextSpanStyle textStyle = null; ////test only *** ////TODO: make this more configurable //if (style != null) //{ // TextSpanStyle defaultBeh = ((TextSpanStyle)style); // if (defaultBeh.FontBold) // { // textStyle = StyleHelper.CreateNewStyle(Color.Black); // } // else // { // textStyle = StyleHelper.CreateNewStyle(Color.Blue); // } //} //else //{ // textStyle = StyleHelper.CreateNewStyle(Color.Blue); //} //internalTextLayerController.DoFormatSelection(textStyle); //if (internalTextLayerController.updateJustCurrentLine) //{ // InvalidateGraphicOfCurrentLineArea(); //} //else //{ // InvalidateGraphics(); //} } break; } } if (textSurfaceEventListener != null) { TextSurfaceEventListener.NotifyKeyDown(textSurfaceEventListener, e.KeyCode); } }