DialogPageDesigner.cs 4.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158
  1. using System.Windows.Forms;
  2. using System.Drawing;
  3. using System.ComponentModel;
  4. using FastReport.Utils;
  5. using FastReport.Forms;
  6. using FastReport.Dialog;
  7. namespace FastReport.Design.PageDesigners.Dialog
  8. {
  9. #if !DEBUG
  10. [DesignTimeVisible(false)]
  11. #endif
  12. internal class DialogPageDesigner : PageDesignerBase
  13. {
  14. #region Fields
  15. private DialogWorkspace workspace;
  16. #endregion
  17. #region Properties
  18. public DialogPage DialogPage
  19. {
  20. get { return Page as DialogPage; }
  21. }
  22. #endregion
  23. #region Private Methods
  24. private void UpdateName()
  25. {
  26. if (Page != null)//need refactor
  27. {
  28. if (Page.Name == "")
  29. Text = Page.ClassName + (Page.ZOrder + 1).ToString();
  30. else
  31. Text = Page.Name;
  32. }
  33. }
  34. private void UpdatePageFormLocation()
  35. {
  36. if (DialogPage == null)
  37. return;
  38. // avoid "bad form owner" bug
  39. Form designerForm = Designer.FindForm();
  40. if (designerForm == null || !designerForm.Visible)
  41. return;
  42. BaseForm form = DialogPage.Form;
  43. form.StartPosition = FormStartPosition.Manual;
  44. form.Location = new Point(-10000, -10000);
  45. form.Show();
  46. form.SendToBack();
  47. // locate the form on the bottom of the designer's screen. This will autoscale the form
  48. // according to the designer's dpi; also the form will not be visible on undo operations.
  49. Screen sc = Screen.FromControl(designerForm);
  50. form.Location = new Point(sc.WorkingArea.Left, sc.WorkingArea.Bottom);
  51. DialogPage.ResetFormBitmap();
  52. Focus();
  53. }
  54. #endregion
  55. #region Public Methods
  56. public override void PageActivated()
  57. {
  58. base.PageActivated();
  59. UpdatePageFormLocation();
  60. }
  61. public override void PageDeactivated()
  62. {
  63. base.PageDeactivated();
  64. DialogPage.Form.Hide();
  65. }
  66. public override void Paste(ObjectCollection list, InsertFrom source)
  67. {
  68. workspace.Paste(list, source);
  69. }
  70. public override void CancelPaste()
  71. {
  72. workspace.CancelPaste();
  73. }
  74. public override void SelectAll()
  75. {
  76. Designer.SelectedObjects.Clear();
  77. foreach (Base c in Page.AllObjects)
  78. {
  79. Designer.SelectedObjects.Add(c);
  80. }
  81. if (Designer.SelectedObjects.Count == 0)
  82. Designer.SelectedObjects.Add(Page);
  83. Designer.SelectionChanged(null);
  84. }
  85. #endregion
  86. #region IDesignerPlugin
  87. public override void SaveState()
  88. {
  89. XmlItem xi = Config.Root.FindItem("Designer").FindItem(Name);
  90. xi.SetProp("ShowGrid", DialogWorkspace.ShowGrid ? "1" : "0");
  91. xi.SetProp("SnapToGrid", DialogWorkspace.SnapToGrid ? "1" : "0");
  92. xi.SetProp("SnapSize", DialogWorkspace.Grid.SnapSize.ToString());
  93. }
  94. public override void RestoreState()
  95. {
  96. XmlItem xi = Config.Root.FindItem("Designer").FindItem(Name);
  97. DialogWorkspace.ShowGrid = xi.GetProp("ShowGrid") == "1";
  98. DialogWorkspace.SnapToGrid = xi.GetProp("SnapToGrid") != "0";
  99. string size = xi.GetProp("SnapSize");
  100. if (size == "")
  101. size = "4";
  102. DialogWorkspace.Grid.SnapSize = int.Parse(size);
  103. }
  104. public override void SelectionChanged()
  105. {
  106. base.SelectionChanged();
  107. UpdateContent();
  108. }
  109. public override void UpdateContent()
  110. {
  111. if (Locked)
  112. return;
  113. base.UpdateContent();
  114. UpdateName();
  115. workspace.Refresh();
  116. }
  117. public override DesignerOptionsPage GetOptionsPage()
  118. {
  119. return new DialogPageOptions(this);
  120. }
  121. public override void UpdateDpiDependencies()
  122. {
  123. base.UpdateDpiDependencies();
  124. UpdatePageFormLocation();
  125. workspace.Refresh();
  126. }
  127. #endregion
  128. public DialogPageDesigner(Designer designer) : base(designer)
  129. {
  130. Name = "Dialog";
  131. workspace = new DialogWorkspace(this);
  132. Controls.Add(workspace);
  133. BackColor = SystemColors.Window;
  134. AutoScroll = true;
  135. }
  136. }
  137. }