123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136 |
- using System;
- using System.Collections.Generic;
- using System.Text;
- using System.Windows.Forms;
- using System.Drawing;
- using FastReport.Design;
- using FastReport.Utils;
- using FastReport.Forms;
- namespace FastReport.Table
- {
- internal class TableCellMenu : TableMenuBase
- {
- #region Fields
- private SelectedObjectCollection selection;
- private TableBase table;
- private TableCell topCell;
- public ContextMenuItem miFormat;
- public ContextMenuItem miMergeSplit;
- public ContextMenuItem miClear;
- public ContextMenuItem miCut;
- public ContextMenuItem miCopy;
- public ContextMenuItem miPaste;
- #endregion
- #region Private Methods
- private void miFormat_Click(object sender, EventArgs e)
- {
- using (FormatEditorForm form = new FormatEditorForm())
- {
- form.TextObject = topCell;
- if (form.ShowDialog() == DialogResult.OK)
- {
- SelectedTextBaseObjects components = new SelectedTextBaseObjects(Designer);
- components.Update();
- components.SetFormat(form.Formats);
- Change();
- }
- }
- }
- private void miMergeSplit_Click(object sender, EventArgs e)
- {
- if (miMergeSplit.Checked)
- {
- Rectangle rect = table.GetSelectionRect();
- // reset spans inside selection
- for (int x = 0; x < rect.Width; x++)
- {
- for (int y = 0; y < rect.Height; y++)
- {
- TableCell cell = table[x + rect.X, y + rect.Y];
- cell.ColSpan = 1;
- cell.RowSpan = 1;
- if (cell != topCell)
- cell.Text = "";
- }
- }
- topCell.ColSpan = rect.Width;
- topCell.RowSpan = rect.Height;
- selection.Clear();
- selection.Add(topCell);
- }
- else
- {
- topCell.ColSpan = 1;
- topCell.RowSpan = 1;
- }
- Change();
- }
- private void miClear_Click(object sender, EventArgs e)
- {
- foreach (Base c in selection)
- {
- if (c is TableCell)
- (c as TableCell).Text = "";
- }
- Change();
- }
- private void miCut_Click(object sender, EventArgs e)
- {
- table.Clipboard.CutCells(table.GetSelectionRect());
- table.CreateUniqueNames();
- Change();
- }
- private void miCopy_Click(object sender, EventArgs e)
- {
- table.Clipboard.CopyCells(table.GetSelectionRect());
- }
- private void miPaste_Click(object sender, EventArgs e)
- {
- table.Clipboard.PasteCells(topCell.Address);
- table.CreateUniqueNames();
- selection.Clear();
- selection.Add(table);
- Change();
- }
- #endregion
- public TableCellMenu(Designer designer) : base(designer)
- {
- selection = Designer.SelectedObjects;
- topCell = selection[0] as TableCell;
- table = topCell.Parent.Parent as TableBase;
- miFormat = CreateMenuItem(Res.Get("ComponentMenu,TextObject,Format"), new EventHandler(miFormat_Click));
- miMergeSplit = CreateMenuItem(217, Res.Get("ComponentMenu,TableCell,Merge"), new EventHandler(miMergeSplit_Click));
- miMergeSplit.CheckOnClick = true;
- miClear = CreateMenuItem(82, Res.Get("ComponentMenu,TextObject,Clear"), new EventHandler(miClear_Click));
- miCut = CreateMenuItem(5, Res.Get("Designer,Menu,Edit,Cut"), new EventHandler(miCut_Click));
- miCut.BeginGroup = true;
- miCopy = CreateMenuItem(6, Res.Get("Designer,Menu,Edit,Copy"), new EventHandler(miCopy_Click));
- miPaste = CreateMenuItem(7, Res.Get("Designer,Menu,Edit,Paste"), new EventHandler(miPaste_Click));
- bool canJoin = selection.Count > 1;
- bool canSplit = selection.Count == 1 && topCell != null && (topCell.ColSpan > 1 || topCell.RowSpan > 1);
- miMergeSplit.Enabled = canJoin || canSplit;
- miMergeSplit.Checked = canSplit;
- if (miMergeSplit.Checked)
- miMergeSplit.Text = Res.Get("ComponentMenu,TableCell,Split");
- miPaste.Enabled = table.Clipboard.CanPasteCells;
- Items.AddRange(new ContextMenuItem[] {
- miFormat, miMergeSplit, miClear,
- miCut, miCopy, miPaste });
- }
- }
- }
|