using System; using System.Collections; using System.Collections.Generic; using System.Runtime.CompilerServices; using System.Windows.Forms; namespace FastReport.Design.PageDesigners.Code { internal interface ITextEditor { string Text { get; set; } void Focus(); void Select(int start, int length); } public enum SyntaxType { None, Cs, Vb, Xml } public abstract class SyntaxEditorBase : Control, ITextEditor { public abstract string SelectedText { get; set; } public abstract bool Modified { get; set; } public abstract bool ShowLineNumbers { get; set; } public abstract bool EnableVirtualSpace { get; set; } public abstract bool ConvertTabsToSpaces { get; set; } public abstract int IndentationSize { get; set; } public abstract SyntaxType SyntaxType { get; set; } public abstract bool AllowCodeCompletion { get; set; } public new event EventHandler TextChanged; protected void OnTextChanged() => TextChanged?.Invoke(this, EventArgs.Empty); public abstract void Cut(); public abstract void Copy(); public abstract void Paste(); public abstract bool CanUndo { get; } public abstract void Undo(); public abstract bool CanRedo { get; } public abstract void Redo(); public abstract void SelectAll(); public abstract new void Focus(); public abstract void Locate(int line, int column); public abstract void Select(int start, int length); public abstract void SetCaretFromMousePosition(System.Drawing.Point pos); // for code completion public abstract void UpdateInternals(Report report); } public enum SyntaxEditorKind { Code, Xml } public static class SyntaxEditorClass { private static Dictionary syntaxEditorTypes; private static Dictionary SyntaxEditorTypes { get { if (syntaxEditorTypes == null) { syntaxEditorTypes = new Dictionary(); syntaxEditorTypes[SyntaxEditorKind.Code] = typeof(AvalonSyntaxEditor); syntaxEditorTypes[SyntaxEditorKind.Xml] = typeof(AvalonSyntaxEditor); } return syntaxEditorTypes; } } internal static SyntaxEditorBase CreateInstance(SyntaxEditorKind editorKind) => Activator.CreateInstance(SyntaxEditorTypes[editorKind]) as SyntaxEditorBase; public static void Register(Type editorType, SyntaxEditorKind editorKind) { if (!typeof(SyntaxEditorBase).IsAssignableFrom(editorType)) throw new ArgumentException("editorType must be of SyntaxEditorBase type"); SyntaxEditorTypes[editorKind] = editorType; } } }