DesignerControl.cs 4.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148
  1. using FastReport.Design.PageDesigners.Dialog;
  2. using FastReport.Utils;
  3. using System.ComponentModel;
  4. using System.Drawing;
  5. using System.Drawing.Drawing2D;
  6. using System.Windows.Forms;
  7. namespace FastReport.Design.RibbonDesigner
  8. {
  9. /// <summary>
  10. /// Represents the Ribbon report designer.
  11. /// </summary>
  12. /// <remarks>
  13. /// This control extends the <see cref="FastReport.Design.Designer"/> control with
  14. /// standard menu, status bar, and Ribbon.
  15. /// </remarks>
  16. [ToolboxItem(true), ToolboxBitmap(typeof(Report), "Resources.DesignerControl.bmp")]
  17. public partial class DesignerControl : Designer
  18. {
  19. #region Fields
  20. private StandardDesigner.DesignerMenu mainMenu;
  21. private StandardDesigner.DesignerStatusBar statusBar;
  22. private Ribbon ribbon;
  23. private Panel ribbonPanel;
  24. private bool showMainMenu;
  25. private bool showStatusBar;
  26. #endregion
  27. #region Properties
  28. /// <summary>
  29. /// Gets the main menu.
  30. /// </summary>
  31. [Browsable(false), DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]
  32. public StandardDesigner.DesignerMenu MainMenu
  33. {
  34. get { return mainMenu; }
  35. }
  36. /// <summary>
  37. /// Gets or sets a value indicating whether the main menu should be displayed or not.
  38. /// </summary>
  39. [SRCategory("Toolbars")]
  40. [DefaultValue(true)]
  41. public bool ShowMainMenu
  42. {
  43. get { return showMainMenu; }
  44. set
  45. {
  46. showMainMenu = value;
  47. mainMenu.Visible = value;
  48. }
  49. }
  50. /// <summary>
  51. /// Gets or sets a value indicating whether the status bar should be displayed or not.
  52. /// </summary>
  53. [SRCategory("Toolbars")]
  54. [DefaultValue(true)]
  55. public bool ShowStatusBar
  56. {
  57. get { return showStatusBar; }
  58. set
  59. {
  60. showStatusBar = value;
  61. statusBar.Visible = value;
  62. }
  63. }
  64. #endregion
  65. #region Private Methods
  66. private void ribbonPanel_Paint(object sender, PaintEventArgs e)
  67. {
  68. var ct = UIStyleUtils.GetColorTable(UIStyle);
  69. Rectangle rect = new Rectangle(0, 0, ribbonPanel.Width, ribbonPanel.Height);
  70. using (var brush = new LinearGradientBrush(rect, ct.Ribbon.GradientBegin, ct.Ribbon.GradientEnd, LinearGradientMode.Vertical))
  71. e.Graphics.FillRectangle(brush, rect);
  72. }
  73. #endregion
  74. #region Protected Methods
  75. /// <inheritdoc/>
  76. protected override void InitPlugins()
  77. {
  78. base.InitPlugins();
  79. ribbonPanel = new Panel();
  80. ribbonPanel.Dock = DockStyle.Top;
  81. ribbonPanel.Paint += ribbonPanel_Paint;
  82. Controls.Add(ribbonPanel);
  83. var shadow = ribbonPanel.SetShadow(DockStyle.Bottom);
  84. UIStyleChanged += (s,e) => shadow.Color = UIStyleUtils.GetColorTable(UIStyle).Ribbon.BorderColor;
  85. mainMenu = new StandardDesigner.DesignerMenu(this);
  86. statusBar = new StandardDesigner.DesignerStatusBar(this);
  87. ribbon = new Ribbon(this);
  88. ribbon.AddQuickAccessControls(mainMenu);
  89. ribbonPanel.Controls.Add(ribbon);
  90. Plugins.AddRange(new IDesignerPlugin[] {
  91. mainMenu, statusBar });
  92. }
  93. #endregion
  94. #region Public Methods
  95. /// <inheritdoc/>
  96. public override void ShowStatus(string location, string size, string text, string locationRightBot)
  97. {
  98. statusBar.UpdateLocationAndSize(location, size, locationRightBot);
  99. statusBar.UpdateText(text);
  100. }
  101. /// <inheritdoc/>
  102. public override void UpdateUIStyle()
  103. {
  104. base.UpdateUIStyle();
  105. ribbon.UpdateUIStyle(UIStyle);
  106. ribbonPanel.Refresh();
  107. }
  108. /// <inheritdoc/>
  109. public override void UpdateDpiDependencies(object sender)
  110. {
  111. base.UpdateDpiDependencies(sender);
  112. ribbonPanel.Height = this.LogicalToDevice(90);
  113. }
  114. internal void UpdateFirstDialogPage()
  115. {
  116. // WPF bug: designer workspace is not initialized if the dialog form is the first page in a report (reason: visible designer form is needed)
  117. if (ActiveReportTab != null && ActiveReportTab.ActivePageDesigner is DialogPageDesigner pd)
  118. pd.UpdateDpiDependencies();
  119. }
  120. #endregion
  121. /// <summary>
  122. /// Initializes a new instance of the <see cref="DesignerControl"/> class with default settings.
  123. /// </summary>
  124. public DesignerControl()
  125. {
  126. ShowMainMenu = true;
  127. ShowStatusBar = true;
  128. }
  129. }
  130. }