MatrixCellMenuBase.cs 6.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176
  1. using System;
  2. using System.Drawing;
  3. using System.Windows.Forms;
  4. using FastReport.Design;
  5. using FastReport.Utils;
  6. using FastReport.Table;
  7. using FastReport.Forms;
  8. namespace FastReport.AdvMatrix
  9. {
  10. internal class MatrixCellMenuBase : TableMenuBase
  11. {
  12. private AdvMatrixObject matrix;
  13. private SelectedObjectCollection selection;
  14. public ContextMenuItem miEdit;
  15. public ContextMenuItem miFormat;
  16. public ContextMenuItem miHyperlink;
  17. public ContextMenuItem miClear;
  18. public ContextMenuItem miMergeSplit;
  19. public ContextMenuItem miCollapseButton;
  20. public ContextMenuItem miSortButton;
  21. public AdvMatrixObject Matrix
  22. {
  23. get { return matrix; }
  24. }
  25. public TableCell Cell
  26. {
  27. get { return selection[0] as TableCell; }
  28. }
  29. private void miEdit_Click(object sender, EventArgs e)
  30. {
  31. Matrix.HandleCellDoubleClick(Cell);
  32. }
  33. private void miFormat_Click(object sender, EventArgs e)
  34. {
  35. using (FormatEditorForm form = new FormatEditorForm())
  36. {
  37. form.TextObject = Cell;
  38. if (form.ShowDialog() == DialogResult.OK)
  39. {
  40. SelectedTextBaseObjects components = new SelectedTextBaseObjects(Designer);
  41. components.Update();
  42. components.SetFormat(form.Formats);
  43. Change();
  44. }
  45. }
  46. }
  47. private void miHyperlink_Click(object sender, EventArgs e)
  48. {
  49. using (HyperlinkEditorForm form = new HyperlinkEditorForm())
  50. {
  51. form.ReportComponent = Cell;
  52. if (Cell.GetMatrixElement() == MatrixElement.Cell)
  53. form.IsMatrixHyperlink = true;
  54. if (form.ShowDialog() == DialogResult.OK)
  55. {
  56. SelectedReportComponents components = new SelectedReportComponents(Designer);
  57. components.Update();
  58. components.SetHyperlink(form.Hyperlink, form.ModifyAppearance, false);
  59. Change();
  60. }
  61. }
  62. }
  63. private void miCollapseButton_Click(object sender, EventArgs e)
  64. {
  65. if (miCollapseButton.Checked)
  66. Cell.AddCollapseButton();
  67. else
  68. Cell.GetCollapseButton().Dispose();
  69. Change();
  70. }
  71. private void miSortButton_Click(object sender, EventArgs e)
  72. {
  73. if (miSortButton.Checked)
  74. Cell.AddSortButton();
  75. else
  76. Cell.GetSortButton().Dispose();
  77. Change();
  78. }
  79. private void miClear_Click(object sender, EventArgs e)
  80. {
  81. foreach (Base c in Designer.SelectedObjects)
  82. {
  83. if (c is TableCell)
  84. (c as TableCell).Text = "";
  85. }
  86. Change();
  87. }
  88. private void miMergeSplit_Click(object sender, EventArgs e)
  89. {
  90. TableCell topCell = Cell;
  91. if (miMergeSplit.Checked)
  92. {
  93. Rectangle rect = matrix.GetSelectionRect();
  94. // reset spans inside selection
  95. for (int x = 0; x < rect.Width; x++)
  96. {
  97. for (int y = 0; y < rect.Height; y++)
  98. {
  99. TableCell cell = matrix[x + rect.X, y + rect.Y];
  100. cell.ColSpan = 1;
  101. cell.RowSpan = 1;
  102. }
  103. }
  104. topCell.ColSpan = rect.Width;
  105. topCell.RowSpan = rect.Height;
  106. selection.Clear();
  107. selection.Add(topCell);
  108. }
  109. else
  110. {
  111. topCell.ColSpan = 1;
  112. topCell.RowSpan = 1;
  113. }
  114. Change();
  115. }
  116. protected override void Change()
  117. {
  118. if (!Designer.IsPreviewPageDesigner)
  119. {
  120. Matrix.BuildTemplate();
  121. Designer.ActiveReportTab.ActivePageDesigner.FillObjects(false);
  122. Matrix.FixParentHeight();
  123. }
  124. Designer.SetModified(Matrix, "Change");
  125. }
  126. public MatrixCellMenuBase(AdvMatrixObject matrix) : base(matrix.Report.Designer)
  127. {
  128. this.matrix = matrix;
  129. selection = Designer.SelectedObjects;
  130. miEdit = CreateMenuItem(68, Res.Get("ComponentMenu,Component,Edit"), miEdit_Click);
  131. miFormat = CreateMenuItem(168, Res.Get("ComponentMenu,TextObject,Format"), miFormat_Click);
  132. miHyperlink = CreateMenuItem(167, Res.Get("ComponentMenu,ReportComponent,Hyperlink"), miHyperlink_Click);
  133. miCollapseButton = CreateMenuItem(Res.Get("ComponentMenu,AdvMatrixHeader,CollapseButton"), miCollapseButton_Click);
  134. miCollapseButton.BeginGroup = true;
  135. miCollapseButton.CheckOnClick = true;
  136. miSortButton = CreateMenuItem(Res.Get("ComponentMenu,AdvMatrixHeader,SortButton"), miSortButton_Click);
  137. miSortButton.CheckOnClick = true;
  138. miClear = CreateMenuItem(82, Res.Get("ComponentMenu,TextObject,Clear"), miClear_Click);
  139. miClear.BeginGroup = true;
  140. miMergeSplit = CreateMenuItem(217, Res.Get("ComponentMenu,TableCell,Merge"), miMergeSplit_Click);
  141. miMergeSplit.CheckOnClick = true;
  142. Items.AddRange(new ContextMenuItem[] { miEdit, miFormat, miHyperlink, miCollapseButton, miSortButton, miClear, miMergeSplit });
  143. miEdit.Enabled = selection.Count == 1;
  144. miCollapseButton.Enabled = miEdit.Enabled && Cell.GetMatrixElement() != MatrixElement.Corner;
  145. miCollapseButton.Checked = Cell.GetCollapseButton() != null;
  146. miSortButton.Enabled = miEdit.Enabled;
  147. miSortButton.Checked = Cell.GetSortButton() != null;
  148. bool canJoin = selection.Count > 1;
  149. bool canSplit = selection.Count == 1 && (Cell.ColSpan > 1 || Cell.RowSpan > 1);
  150. miMergeSplit.Enabled = canJoin || canSplit;
  151. miMergeSplit.Checked = canSplit;
  152. if (miMergeSplit.Checked)
  153. miMergeSplit.Text = Res.Get("ComponentMenu,TableCell,Split");
  154. }
  155. }
  156. }