123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210 |
- using FastReport.Code;
- using FastReport.Data;
- using FastReport.Design.ToolWindows;
- using FastReport.Forms;
- using FastReport.Utils;
- using System;
- using System.Drawing;
- using System.Reflection;
- using System.Windows.Forms;
- namespace FastReport.Design.PageDesigners.Code
- {
- internal interface ITextEditor
- {
- string Text { get; set; }
- bool Focus();
- void Select(int start, int length);
- }
- internal class SyntaxEditorBase : TextBox, ITextEditor
- {
- public void Locate(int line, int column)
- {
- // nope...
- }
- }
- internal class TextEditor : SyntaxEditorBase
- {
- }
- internal class CodePageDesigner : PageDesignerBase
- {
- #region Fields
- private bool canModify;
- #endregion
- #region Properties
- public TextEditor Edit { get; private set; }
- public string Script
- {
- get => Edit.Text;
- set => SetText(value);
- }
- #endregion
- #region Private Methods
- private void CreateEdit()
- {
- Edit = new TextEditor();
- Edit.Multiline = true;
- Edit.AcceptsReturn = true;
- Edit.AcceptsTab = true;
- Edit.Font = DrawUtils.FixedFont;
- Edit.Dock = DockStyle.Fill;
- Edit.BorderStyle = BorderStyle.None;
- Edit.MaxLength = int.MaxValue;
- Edit.AllowDrop = true;
- Edit.DragOver += new DragEventHandler(Edit_DragOver);
- Edit.DragDrop += new DragEventHandler(Edit_DragDrop);
- Controls.Add(Edit);
- Edit.ScrollBars = ScrollBars.Both;
- Edit.TextChanged += new EventHandler(Edit_TextChanged);
- Edit.ImeMode = ImeMode.On;
- }
- private void SetText(string value)
- {
- canModify = false;
- Edit.Text = value;
- Edit.Modified = false;
- canModify = true;
- }
- private void Edit_DragOver(object sender, DragEventArgs e)
- {
- int index = Edit.GetCharIndexFromPosition(Edit.PointToClient(new Point(e.X, e.Y)));
- Edit.Select(index, 0);
- e.Effect = e.AllowedEffect;
- }
- private void Edit_DragDrop(object sender, DragEventArgs e)
- {
- DictionaryWindow.DraggedItem item = DictionaryWindow.DragUtils.GetOne(e);
- if (item == null)
- return;
- CodeHelperBase codeHelper = Designer.ActiveReport.Report.CodeHelper;
- string text = "";
- if (item.obj is Column)
- text = codeHelper.ReplaceColumnName(item.text, (item.obj as Column).DataType);
- else if (item.obj is SystemVariable)
- text = codeHelper.ReplaceVariableName(item.obj as Parameter);
- else if (item.obj is Parameter)
- text = codeHelper.ReplaceParameterName(item.obj as Parameter);
- else if (item.obj is Total)
- text = codeHelper.ReplaceTotalName(item.text);
- else if (item.obj is MethodInfo)
- text = item.text;
- else
- text = "Report.Calc(\"" + item.text + "\")";
- Edit.SelectedText = text;
- Edit.Focus();
- }
- private void Edit_TextChanged(object sender, EventArgs e)
- {
- if (canModify)
- Designer.SetModified(null, "no-undo");
- }
- public void CommitChanges()
- {
- if (Edit.Modified)
- {
- Edit.Modified = false;
- Designer.SetModified(this, "Script");
- }
- }
- #endregion
- #region Public Methods
- public void UpdateFont()
- {
- }
- public void UpdateLanguage()
- {
- // do nothing
- }
- public override bool CanCopy() => true;
- public override void Copy()
- {
- Edit.Copy();
- }
- public override void Cut()
- {
- Edit.Cut();
- }
- public override bool CanPaste() => true;
- public override void Paste()
- {
- Edit.Paste();
- }
- public override bool CanUndo()
- {
- return Edit.CanUndo;
- }
- public override void Undo()
- {
- Edit.Undo();
- }
- public override void SelectAll()
- {
- Edit.SelectAll();
- }
- public override void ResetModified()
- {
- Edit.Modified = false;
- }
- public override void FillObjects(bool resetSelection)
- {
- // do nothing
- }
- public override void PageDeactivated()
- {
- base.PageDeactivated();
- CommitChanges();
- }
- #endregion
- #region IDesignerPlugin
- public override void SaveState()
- {
- CodePageSettings.SaveState();
- }
- public override void RestoreState()
- {
- }
- public override DesignerOptionsPage GetOptionsPage()
- {
- return new CodePageOptions(this);
- }
- #endregion
- public CodePageDesigner(Designer designer) : base(designer)
- {
- Name = "Code";
- CreateEdit();
- }
- }
- }
|