TextObjectBaseMenu.cs 3.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394
  1. using System;
  2. using System.Windows.Forms;
  3. using FastReport.Design;
  4. using FastReport.Utils;
  5. using FastReport.Forms;
  6. namespace FastReport
  7. {
  8. /// <summary>
  9. /// The class introduces some menu items specific to the <b>TextObjectBase</b>.
  10. /// </summary>
  11. public class TextObjectBaseMenu : BreakableComponentMenu
  12. {
  13. #region Fields
  14. /// <summary>
  15. /// The "Format" menu item.
  16. /// </summary>
  17. public ContextMenuItem miFormat;
  18. /// <summary>
  19. /// The "Allow Expressions" menu item.
  20. /// </summary>
  21. public ContextMenuItem miAllowExpressions;
  22. /// <summary>
  23. /// The "Hide Zeros" menu item.
  24. /// </summary>
  25. public ContextMenuItem miHideZeros;
  26. private SelectedTextBaseObjects textObjects;
  27. #endregion
  28. #region Private Methods
  29. private void miFormat_Click(object sender, EventArgs e)
  30. {
  31. using (FormatEditorForm form = new FormatEditorForm())
  32. {
  33. form.TextObject = textObjects.First;
  34. if (form.ShowDialog() == DialogResult.OK)
  35. {
  36. textObjects.SetFormat(form.Formats);
  37. Change();
  38. }
  39. }
  40. }
  41. private void miAllowExpressions_Click(object sender, EventArgs e)
  42. {
  43. textObjects.SetAllowExpressions(miAllowExpressions.Checked);
  44. Change();
  45. }
  46. private void miHideZeros_Click(object sender, EventArgs e)
  47. {
  48. textObjects.SetHideZeros(miHideZeros.Checked);
  49. Change();
  50. }
  51. #endregion Private Methods
  52. /// <summary>
  53. /// Initializes a new instance of the <b>TextObjectBaseMenu</b>
  54. /// class with default settings.
  55. /// </summary>
  56. /// <param name="designer">The reference to a report designer.</param>
  57. public TextObjectBaseMenu(Designer designer) : base(designer)
  58. {
  59. textObjects = new SelectedTextBaseObjects(designer);
  60. textObjects.Update();
  61. MyRes res = new MyRes("ComponentMenu,TextObject");
  62. miFormat = CreateMenuItem(168, res.Get("Format"), new EventHandler(miFormat_Click));
  63. miAllowExpressions = CreateMenuItem(res.Get("AllowExpressions"), new EventHandler(miAllowExpressions_Click));
  64. miHideZeros = CreateMenuItem(res.Get("HideZeros"), new EventHandler(miHideZeros_Click));
  65. miAllowExpressions.BeginGroup = true;
  66. miAllowExpressions.CheckOnClick = true;
  67. miHideZeros.CheckOnClick = true;
  68. int insertPos = Items.IndexOf(miEdit) + 1;
  69. Items.Insert(insertPos, miFormat);
  70. insertPos = Items.IndexOf(miCut);
  71. Items.Insert(insertPos, miAllowExpressions);
  72. Items.Insert(insertPos + 1, miHideZeros);
  73. TextObjectBase obj = textObjects.First;
  74. bool enabled = !obj.HasRestriction(Restrictions.DontModify);
  75. miAllowExpressions.Enabled = enabled;
  76. miAllowExpressions.Checked = obj.AllowExpressions && enabled;
  77. miHideZeros.Enabled = enabled;
  78. miHideZeros.Checked = obj.HideZeros && enabled;
  79. }
  80. }
  81. }