123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274 |
- using FastReport.Data;
- using FastReport.Design.PageDesigners.Page;
- using FastReport.Forms;
- using FastReport.Utils;
- using System;
- using System.Drawing;
- using System.Windows.Forms;
- namespace FastReport
- {
- partial class TextObject : IHasEditor
- {
- #region Fields
- private TextBox textBox;
- internal bool dragAccept;
- #endregion
- #region Properties
- /// <inheritdoc/>
- public override float Left
- {
- get { return base.Left; }
- set
- {
- base.Left = value;
- if (IsEditing)
- UpdateEditorPosition();
- }
- }
- /// <inheritdoc/>
- public override float Top
- {
- get { return base.Top; }
- set
- {
- base.Top = value;
- if (IsEditing)
- UpdateEditorPosition();
- }
- }
- /// <inheritdoc/>
- public override float Width
- {
- get { return base.Width; }
- set
- {
- base.Width = value;
- if (IsEditing)
- UpdateEditorPosition();
- }
- }
- /// <inheritdoc/>
- public override float Height
- {
- get { return base.Height; }
- set
- {
- base.Height = value;
- if (IsEditing)
- UpdateEditorPosition();
- }
- }
- private bool IsEditing
- {
- get { return IsDesigning && textBox != null; }
- }
- #endregion
- #region Private Methods
- //private bool ShouldSerializeFont()
- //{
- // return Font.Name != "Arial" || Font.Size != 10 || Font.Style != FontStyle.Regular;
- //}
- private bool ShouldSerializeTextFill()
- {
- return !(TextFill is SolidFill) || (TextFill as SolidFill).Color != Color.Black;
- }
- private void UpdateEditorPosition()
- {
- var offset = (Report.Designer.ActiveReportTab.ActivePageDesigner as ReportPageDesigner).Workspace.Offset;
- textBox.Location = new Point((int)Math.Round(AbsLeft * Report.Designer.ZoomDpi) + offset.X + 1,
- (int)Math.Round(AbsTop * Report.Designer.ZoomDpi) + offset.Y + 1);
- textBox.Size = new Size((int)Math.Round(Width * Report.Designer.ZoomDpi) - 1,
- (int)Math.Round(Height * Report.Designer.ZoomDpi) - 1);
- }
- private void FTextBox_KeyDown(object sender, KeyEventArgs e)
- {
- if (e.KeyCode == Keys.Escape)
- {
- FinishEdit(false);
- e.Handled = true;
- }
- if (e.Control && e.KeyCode == Keys.Enter)
- {
- FinishEdit(true);
- e.Handled = true;
- }
- }
- #endregion
- #region Public Methods
- /// <inheritdoc/>
- public override void AssignFormat(ReportComponentBase source)
- {
- base.AssignFormat(source);
- TextObject src = source as TextObject;
- if (src == null)
- return;
- HorzAlign = src.HorzAlign;
- VertAlign = src.VertAlign;
- Angle = src.Angle;
- Underlines = src.Underlines;
- Font = src.Font;
- TextFill = src.TextFill.Clone();
- TextOutline.Assign(src.TextOutline);
- Trimming = src.Trimming;
- FontWidthRatio = src.FontWidthRatio;
- FirstTabOffset = src.FirstTabOffset;
- TabWidth = src.TabWidth;
- Clip = src.Clip;
- Wysiwyg = src.Wysiwyg;
- LineHeight = src.LineHeight;
- TextRenderType = src.TextRenderType;
- ParagraphOffset = src.ParagraphOffset;
- }
- /// <inheritdoc/>
- public override void HandleDragOver(FRMouseEventArgs e)
- {
- if (PointInObject(new PointF(e.x, e.y)) && e.DragSource is TextObject)
- e.handled = true;
- dragAccept = e.handled;
- }
- /// <inheritdoc/>
- public override void HandleDragDrop(FRMouseEventArgs e)
- {
- Text = (e.DragSource as TextObject).Text;
- dragAccept = false;
- }
- /// <inheritdoc/>
- public override void HandleKeyDown(Control sender, KeyEventArgs e)
- {
- if (IsSelected && e.KeyCode == Keys.Enter && HasFlag(Flags.CanEdit) && !HasRestriction(Restrictions.DontEdit))
- {
- textBox = new TextBox();
- #if (WPF || AVALONIA)
- textBox.Font = new Font(Font.Name, Font.Size * Report.Designer.Zoom, Font.Style);
- #else
- textBox.Font = new Font(Font.Name, Font.Size * Report.Designer.ZoomDpi * DrawUtils.ScreenDpiFX, Font.Style);
- #endif
- textBox.BorderStyle = BorderStyle.None;
- textBox.Multiline = true;
- textBox.AcceptsTab = true;
- if (Fill is SolidFill)
- textBox.BackColor = Color.FromArgb(255, (Fill as SolidFill).Color);
- if (TextFill is SolidFill)
- textBox.ForeColor = Color.FromArgb(255, (TextFill as SolidFill).Color);
- textBox.Text = Text;
- textBox.KeyDown += new KeyEventHandler(FTextBox_KeyDown);
- sender.Controls.Add(textBox);
- UpdateEditorPosition();
- textBox.SelectAll();
- textBox.Focus();
- e.Handled = true;
- }
- }
- /// <inheritdoc/>
- public override void OnMouseDown(MouseEventArgs e)
- {
- if (Editable && !Config.WebMode && InvokeEditor())
- {
- if (Page != null)
- {
- Page.NeedModify = true;
- Page.NeedRefresh = true;
- }
- }
- else
- base.OnMouseDown(e);
- }
- /// <inheritdoc/>
- public override void SelectionChanged()
- {
- FinishEdit(true);
- }
- /// <inheritdoc/>
- public override ContextMenuBase GetContextMenu()
- {
- return new TextObjectMenu(Report.Designer);
- }
- /// <inheritdoc/>
- public override SmartTagBase GetSmartTag()
- {
- return new TextObjectSmartTag(this);
- }
- /// <inheritdoc/>
- public virtual bool InvokeEditor()
- {
- using (TextEditorForm form = new TextEditorForm(Report))
- {
- form.ExpressionText = Text;
- form.Brackets = Brackets;
- form.HideDataBar = Report.IsPreviewing;
- if (form.ShowDialog() == DialogResult.OK)
- {
- Text = form.ExpressionText;
- return true;
- }
- }
- return false;
- }
- internal virtual void FinishEdit(bool accept)
- {
- if (textBox == null)
- return;
- if (textBox.Modified && accept)
- {
- Text = textBox.Text;
- if (Report != null)
- Report.Designer.SetModified(null, "Change", Name);
- }
- textBox.Parent.Focus();
- textBox.Dispose();
- textBox = null;
- }
- /// <inheritdoc/>
- public override string GetDisplayText()
- {
- if (IsDesigning && ReportWorkspace.SimplifyDBFields)
- {
- if (Text.StartsWith("[") && Text.EndsWith("]"))
- {
- string complexName = Text.Substring(1, Text.Length - 2);
- Column column = DataHelper.GetColumn(Report.Dictionary, complexName);
- if (column != null)
- return "[" + column.Alias + "]";
- }
- }
- return Text;
- }
- #endregion
- private void DrawDesign(FRPaintEventArgs e)
- {
- if (dragAccept)
- DrawDragAcceptFrame(e, Color.Silver);
- }
- }
- }
|