MatrixCellMenuBase.cs 6.4 KB

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