ReportComponentBaseMenu.cs 4.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137
  1. using FastReport.Design;
  2. using FastReport.Utils;
  3. using System;
  4. namespace FastReport
  5. {
  6. /// <summary>
  7. /// The class introduces some menu items specific
  8. /// to the <b>ReportComponentBase</b>.
  9. /// </summary>
  10. public class ReportComponentBaseMenu : ComponentBaseMenu
  11. {
  12. #region Fields
  13. /// <summary>
  14. /// The "Can Grow" menu item.
  15. /// </summary>
  16. public ContextMenuItem miCanGrow;
  17. /// <summary>
  18. /// The "Can Shrink" menu item.
  19. /// </summary>
  20. public ContextMenuItem miCanShrink;
  21. /// <summary>
  22. /// The "Grow to Bottom" menu item.
  23. /// </summary>
  24. public ContextMenuItem miGrowToBottom;
  25. /// <summary>
  26. /// The "Hyperlink" menu item.
  27. /// </summary>
  28. public ContextMenuItem miHyperlink;
  29. /// <summary>
  30. /// The "Style" menu item.
  31. /// </summary>
  32. public ContextMenuItem miStyle;
  33. #endregion Fields
  34. #region Private Methods
  35. private void miCanGrow_Click(object sender, EventArgs e)
  36. {
  37. Designer.SelectedReportComponents.SetCanGrow(miCanGrow.Checked);
  38. }
  39. private void miCanShrink_Click(object sender, EventArgs e)
  40. {
  41. Designer.SelectedReportComponents.SetCanShrink(miCanShrink.Checked);
  42. }
  43. private void miGrowToBottom_Click(object sender, EventArgs e)
  44. {
  45. Designer.SelectedReportComponents.SetGrowToBottom(miGrowToBottom.Checked);
  46. }
  47. private void miHyperlink_Click(object sender, EventArgs e)
  48. {
  49. Designer.SelectedReportComponents.InvokeHyperlinkEditor();
  50. }
  51. private void miStyle_Click(object sender, EventArgs e)
  52. {
  53. ContextMenuItem subItem = sender as ContextMenuItem;
  54. ReportComponentBase first = Designer.SelectedReportComponents.First as ReportComponentBase;
  55. if (first.Style == subItem.Text)
  56. {
  57. Designer.SelectedReportComponents.SetStyle("");
  58. }
  59. else
  60. {
  61. Designer.SelectedReportComponents.SetStyle(subItem.Text);
  62. }
  63. }
  64. #endregion Private Methods
  65. /// <summary>
  66. /// Initializes a new instance of the <b>ReportComponentBaseMenu</b>
  67. /// class with default settings.
  68. /// </summary>
  69. /// <param name="designer">The reference to a report designer.</param>
  70. public ReportComponentBaseMenu(Designer designer) : base(designer)
  71. {
  72. miCanGrow = CreateMenuItem(Res.Get("ComponentMenu,ReportComponent,CanGrow"), new EventHandler(miCanGrow_Click));
  73. miCanGrow.CheckOnClick = true;
  74. miCanGrow.BeginGroup = true;
  75. miCanShrink = CreateMenuItem(Res.Get("ComponentMenu,ReportComponent,CanShrink"), new EventHandler(miCanShrink_Click));
  76. miCanShrink.CheckOnClick = true;
  77. miGrowToBottom = CreateMenuItem(Res.Get("ComponentMenu,ReportComponent,GrowToBottom"), new EventHandler(miGrowToBottom_Click));
  78. miGrowToBottom.CheckOnClick = true;
  79. miHyperlink = CreateMenuItem(167, Res.Get("ComponentMenu,ReportComponent,Hyperlink"), new EventHandler(miHyperlink_Click));
  80. miStyle = CreateMenuItem(Res.Get("ComponentMenu,ReportComponent,Style"));
  81. int insertPos = Items.IndexOf(miEdit) + 1;
  82. Items.Insert(insertPos, miStyle);
  83. Items.Insert(insertPos + 1, miHyperlink);
  84. insertPos = Items.IndexOf(miCut);
  85. Items.Insert(insertPos, miCanGrow);
  86. Items.Insert(insertPos + 1, miCanShrink);
  87. Items.Insert(insertPos + 2, miGrowToBottom);
  88. if (!miEdit.Visible)
  89. miStyle.BeginGroup = true;
  90. bool enabled = Designer.SelectedReportComponents.Enabled;
  91. miCanGrow.Enabled = enabled;
  92. miCanShrink.Enabled = enabled;
  93. miGrowToBottom.Enabled = enabled;
  94. miStyle.Enabled = enabled && Designer.Report.Styles.Count > 0;
  95. if (miStyle.Enabled)
  96. {
  97. ReportComponentBase first = Designer.SelectedReportComponents.First;
  98. foreach (Style style in Designer.Report.Styles)
  99. {
  100. ContextMenuItem subItem = CreateMenuItem(style.Name, miStyle_Click);
  101. if (first.Style == style.Name)
  102. {
  103. subItem.Checked = true;
  104. }
  105. miStyle.DropDownItems.Add(subItem);
  106. }
  107. }
  108. if (enabled)
  109. {
  110. ReportComponentBase first = Designer.SelectedReportComponents.First;
  111. miCanGrow.Checked = first.CanGrow;
  112. miCanShrink.Checked = first.CanShrink;
  113. miGrowToBottom.Checked = first.GrowToBottom;
  114. }
  115. }
  116. }
  117. }