123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190 |
- using FastReport.Design;
- using FastReport.Utils;
- using System;
- using System.ComponentModel;
- using System.Drawing;
- using System.Windows.Forms;
- namespace FastReport.Controls
- {
- internal class ToolStripUndoButton : ToolStripSplitButton
- {
- public ToolStripUndoButton(Designer designer)
- {
- DisplayStyle = ToolStripItemDisplayStyle.Image;
- DropDown = new UndoDropDown(designer);
- ButtonClick += designer.cmdUndo.Invoke;
- }
- }
- internal class ToolStripRedoButton : ToolStripSplitButton
- {
- public ToolStripRedoButton(Designer designer)
- {
- DisplayStyle = ToolStripItemDisplayStyle.Image;
- DropDown = new RedoDropDown(designer);
- ButtonClick += designer.cmdRedo.Invoke;
- }
- }
- internal class UndoRedoDropDown : ToolStripDropDown
- {
- private bool updating;
- private int actionsCount;
- protected Designer designer;
- protected ListBox lbxActions;
- protected Label lblUndoRedo;
- protected ToolStripControlHost actionsHost;
- protected ToolStripControlHost labelHost;
- private void SetSelected(int index)
- {
- if (updating)
- return;
- updating = true;
- int saveTop = lbxActions.TopIndex;
- lbxActions.BeginUpdate();
- lbxActions.SelectedIndices.Clear();
- if (lbxActions.Items.Count > 0)
- {
- for (int i = index; i >= 0; i--)
- lbxActions.SelectedIndices.Add(i);
- }
- lbxActions.TopIndex = saveTop;
- lbxActions.EndUpdate();
- UpdateLabel();
- updating = false;
- }
- private void lbxActions_MouseMove(object sender, MouseEventArgs e)
- {
- int index = lbxActions.IndexFromPoint(e.X, e.Y);
- SetSelected(index);
- actionsCount = lbxActions.SelectedItems.Count;
- }
- private void lbxActions_MouseDown(object sender, MouseEventArgs e)
- {
- Close(ToolStripDropDownCloseReason.ItemClicked);
- DoUndoRedo(actionsCount);
- }
- private void UpdateSizes()
- {
- lbxActions.Size = designer.LogicalToDevice(new Size(150, 200));
- lblUndoRedo.Size = designer.LogicalToDevice(new Size(150, 30));
- }
- protected virtual void PopulateItems()
- {
- }
- protected virtual void UpdateLabel()
- {
- }
- protected virtual void DoUndoRedo(int actionsCount)
- {
- }
- protected override void OnOpening(CancelEventArgs e)
- {
- base.OnOpening(e);
- PopulateItems();
- UpdateSizes();
- SetSelected(0);
- }
- public UndoRedoDropDown(Designer designer)
- : base()
- {
- this.designer = designer;
- Padding = new Padding(1);
- lbxActions = new ListBox();
- lbxActions.Dock = DockStyle.Fill;
- lbxActions.BorderStyle = BorderStyle.None;
- lbxActions.SelectionMode = SelectionMode.MultiSimple;
- lbxActions.MouseMove += new MouseEventHandler(lbxActions_MouseMove);
- lbxActions.MouseDown += new MouseEventHandler(lbxActions_MouseDown);
- actionsHost = new ToolStripControlHost(lbxActions);
- actionsHost.AutoSize = false;
- actionsHost.Size = new Size(150, 250);
- Items.Add(actionsHost);
- lblUndoRedo = new Label();
- lblUndoRedo.Dock = DockStyle.Fill;
- lblUndoRedo.AutoSize = false;
- lblUndoRedo.TextAlign = ContentAlignment.MiddleCenter;
- lblUndoRedo.Text = "test";
- lblUndoRedo.BackColor = Color.Transparent;
- labelHost = new ToolStripControlHost(lblUndoRedo);
- labelHost.AutoSize = false;
- labelHost.Size = new Size(100, 30);
- Items.Add(labelHost);
- }
- }
- internal class UndoDropDown : UndoRedoDropDown
- {
- protected override void PopulateItems()
- {
- lbxActions.Items.Clear();
- if (designer.ActiveReport != null)
- {
- string[] undoNames = designer.ActiveReportTab.UndoRedo.UndoNames;
- foreach (string s in undoNames)
- {
- lbxActions.Items.Add(s);
- }
- }
- }
- protected override void UpdateLabel()
- {
- lblUndoRedo.Text = String.Format(Res.Get("Designer,UndoRedo,UndoN"), lbxActions.SelectedItems.Count);
- }
- protected override void DoUndoRedo(int actionsCount)
- {
- designer.cmdUndo.Undo(actionsCount);
- }
- public UndoDropDown(Designer designer)
- : base(designer)
- {
- }
- }
- internal class RedoDropDown : UndoRedoDropDown
- {
- protected override void PopulateItems()
- {
- lbxActions.Items.Clear();
- if (designer.ActiveReport != null)
- {
- string[] undoNames = designer.ActiveReportTab.UndoRedo.RedoNames;
- foreach (string s in undoNames)
- {
- lbxActions.Items.Add(s);
- }
- }
- }
- protected override void UpdateLabel()
- {
- lblUndoRedo.Text = String.Format(Res.Get("Designer,UndoRedo,RedoN"), lbxActions.SelectedItems.Count);
- }
- protected override void DoUndoRedo(int actionsCount)
- {
- designer.cmdRedo.Redo(actionsCount);
- }
- public RedoDropDown(Designer designer)
- : base(designer)
- {
- }
- }
- }
|