123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158 |
- using System.Windows.Forms;
- using System.Drawing;
- using System.ComponentModel;
- using FastReport.Utils;
- using FastReport.Forms;
- using FastReport.Dialog;
- namespace FastReport.Design.PageDesigners.Dialog
- {
- #if !DEBUG
- [DesignTimeVisible(false)]
- #endif
- internal class DialogPageDesigner : PageDesignerBase
- {
- #region Fields
- private DialogWorkspace workspace;
- #endregion
- #region Properties
- public DialogPage DialogPage
- {
- get { return Page as DialogPage; }
- }
- #endregion
- #region Private Methods
- private void UpdateName()
- {
- if (Page != null)//need refactor
- {
- if (Page.Name == "")
- Text = Page.ClassName + (Page.ZOrder + 1).ToString();
- else
- Text = Page.Name;
- }
- }
- private void UpdatePageFormLocation()
- {
- if (DialogPage == null)
- return;
- // avoid "bad form owner" bug
- Form designerForm = Designer.FindForm();
- if (designerForm == null || !designerForm.Visible)
- return;
- BaseForm form = DialogPage.Form;
- form.StartPosition = FormStartPosition.Manual;
- form.Location = new Point(-10000, -10000);
- form.Show();
- form.SendToBack();
- // locate the form on the bottom of the designer's screen. This will autoscale the form
- // according to the designer's dpi; also the form will not be visible on undo operations.
- Screen sc = Screen.FromControl(designerForm);
- form.Location = new Point(sc.WorkingArea.Left, sc.WorkingArea.Bottom);
- DialogPage.ResetFormBitmap();
- Focus();
- }
- #endregion
- #region Public Methods
- public override void PageActivated()
- {
- base.PageActivated();
- UpdatePageFormLocation();
- }
- public override void PageDeactivated()
- {
- base.PageDeactivated();
- DialogPage.Form.Hide();
- }
- public override void Paste(ObjectCollection list, InsertFrom source)
- {
- workspace.Paste(list, source);
- }
- public override void CancelPaste()
- {
- workspace.CancelPaste();
- }
- public override void SelectAll()
- {
- Designer.SelectedObjects.Clear();
- foreach (Base c in Page.AllObjects)
- {
- Designer.SelectedObjects.Add(c);
- }
- if (Designer.SelectedObjects.Count == 0)
- Designer.SelectedObjects.Add(Page);
- Designer.SelectionChanged(null);
- }
- #endregion
- #region IDesignerPlugin
- public override void SaveState()
- {
- XmlItem xi = Config.Root.FindItem("Designer").FindItem(Name);
- xi.SetProp("ShowGrid", DialogWorkspace.ShowGrid ? "1" : "0");
- xi.SetProp("SnapToGrid", DialogWorkspace.SnapToGrid ? "1" : "0");
- xi.SetProp("SnapSize", DialogWorkspace.Grid.SnapSize.ToString());
- }
- public override void RestoreState()
- {
- XmlItem xi = Config.Root.FindItem("Designer").FindItem(Name);
- DialogWorkspace.ShowGrid = xi.GetProp("ShowGrid") == "1";
- DialogWorkspace.SnapToGrid = xi.GetProp("SnapToGrid") != "0";
- string size = xi.GetProp("SnapSize");
- if (size == "")
- size = "4";
- DialogWorkspace.Grid.SnapSize = int.Parse(size);
- }
- public override void SelectionChanged()
- {
- base.SelectionChanged();
- UpdateContent();
- }
- public override void UpdateContent()
- {
- if (Locked)
- return;
- base.UpdateContent();
- UpdateName();
- workspace.Refresh();
- }
- public override DesignerOptionsPage GetOptionsPage()
- {
- return new DialogPageOptions(this);
- }
- public override void UpdateDpiDependencies()
- {
- base.UpdateDpiDependencies();
- UpdatePageFormLocation();
- workspace.Refresh();
- }
- #endregion
- public DialogPageDesigner(Designer designer) : base(designer)
- {
- Name = "Dialog";
- workspace = new DialogWorkspace(this);
- Controls.Add(workspace);
- BackColor = SystemColors.Window;
- AutoScroll = true;
- }
- }
- }
|