TableCellMenu.cs 4.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Text;
  4. using System.Windows.Forms;
  5. using System.Drawing;
  6. using FastReport.Design;
  7. using FastReport.Utils;
  8. using FastReport.Forms;
  9. namespace FastReport.Table
  10. {
  11. internal class TableCellMenu : TableMenuBase
  12. {
  13. #region Fields
  14. private SelectedObjectCollection selection;
  15. private TableBase table;
  16. private TableCell topCell;
  17. public ContextMenuItem miFormat;
  18. public ContextMenuItem miMergeSplit;
  19. public ContextMenuItem miClear;
  20. public ContextMenuItem miCut;
  21. public ContextMenuItem miCopy;
  22. public ContextMenuItem miPaste;
  23. #endregion
  24. #region Private Methods
  25. private void miFormat_Click(object sender, EventArgs e)
  26. {
  27. using (FormatEditorForm form = new FormatEditorForm())
  28. {
  29. form.TextObject = topCell;
  30. if (form.ShowDialog() == DialogResult.OK)
  31. {
  32. SelectedTextBaseObjects components = new SelectedTextBaseObjects(Designer);
  33. components.Update();
  34. components.SetFormat(form.Formats);
  35. Change();
  36. }
  37. }
  38. }
  39. private void miMergeSplit_Click(object sender, EventArgs e)
  40. {
  41. if (miMergeSplit.Checked)
  42. {
  43. Rectangle rect = table.GetSelectionRect();
  44. // reset spans inside selection
  45. for (int x = 0; x < rect.Width; x++)
  46. {
  47. for (int y = 0; y < rect.Height; y++)
  48. {
  49. TableCell cell = table[x + rect.X, y + rect.Y];
  50. cell.ColSpan = 1;
  51. cell.RowSpan = 1;
  52. if (cell != topCell)
  53. cell.Text = "";
  54. }
  55. }
  56. topCell.ColSpan = rect.Width;
  57. topCell.RowSpan = rect.Height;
  58. selection.Clear();
  59. selection.Add(topCell);
  60. }
  61. else
  62. {
  63. topCell.ColSpan = 1;
  64. topCell.RowSpan = 1;
  65. }
  66. Change();
  67. }
  68. private void miClear_Click(object sender, EventArgs e)
  69. {
  70. foreach (Base c in selection)
  71. {
  72. if (c is TableCell)
  73. (c as TableCell).Text = "";
  74. }
  75. Change();
  76. }
  77. private void miCut_Click(object sender, EventArgs e)
  78. {
  79. table.Clipboard.CutCells(table.GetSelectionRect());
  80. table.CreateUniqueNames();
  81. Change();
  82. }
  83. private void miCopy_Click(object sender, EventArgs e)
  84. {
  85. table.Clipboard.CopyCells(table.GetSelectionRect());
  86. }
  87. private void miPaste_Click(object sender, EventArgs e)
  88. {
  89. table.Clipboard.PasteCells(topCell.Address);
  90. table.CreateUniqueNames();
  91. selection.Clear();
  92. selection.Add(table);
  93. Change();
  94. }
  95. #endregion
  96. public TableCellMenu(Designer designer) : base(designer)
  97. {
  98. selection = Designer.SelectedObjects;
  99. topCell = selection[0] as TableCell;
  100. table = topCell.Parent.Parent as TableBase;
  101. miFormat = CreateMenuItem(Res.Get("ComponentMenu,TextObject,Format"), new EventHandler(miFormat_Click));
  102. miMergeSplit = CreateMenuItem(217, Res.Get("ComponentMenu,TableCell,Merge"), new EventHandler(miMergeSplit_Click));
  103. miMergeSplit.CheckOnClick = true;
  104. miClear = CreateMenuItem(82, Res.Get("ComponentMenu,TextObject,Clear"), new EventHandler(miClear_Click));
  105. miCut = CreateMenuItem(5, Res.Get("Designer,Menu,Edit,Cut"), new EventHandler(miCut_Click));
  106. miCut.BeginGroup = true;
  107. miCopy = CreateMenuItem(6, Res.Get("Designer,Menu,Edit,Copy"), new EventHandler(miCopy_Click));
  108. miPaste = CreateMenuItem(7, Res.Get("Designer,Menu,Edit,Paste"), new EventHandler(miPaste_Click));
  109. bool canJoin = selection.Count > 1;
  110. bool canSplit = selection.Count == 1 && topCell != null && (topCell.ColSpan > 1 || topCell.RowSpan > 1);
  111. miMergeSplit.Enabled = canJoin || canSplit;
  112. miMergeSplit.Checked = canSplit;
  113. if (miMergeSplit.Checked)
  114. miMergeSplit.Text = Res.Get("ComponentMenu,TableCell,Split");
  115. miPaste.Enabled = table.Clipboard.CanPasteCells;
  116. Items.AddRange(new ContextMenuItem[] {
  117. miFormat, miMergeSplit, miClear,
  118. miCut, miCopy, miPaste });
  119. }
  120. }
  121. }