123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203 |
- using FastReport.Design;
- using FastReport.DevComponents.DotNetBar;
- using FastReport.Utils;
- using System.Drawing;
- using System.Windows.Forms;
- using System;
- namespace FastReport.Controls
- {
- internal class UndoButtonItem : ButtonItem
- {
- private UndoDropDown undoDropDown;
- public UndoButtonItem(Designer designer)
- {
- undoDropDown = new UndoDropDown(designer, this);
- Click += designer.cmdUndo.Invoke;
- }
- }
- internal class RedoButtonItem : ButtonItem
- {
- private RedoDropDown redoDropDown;
- public RedoButtonItem(Designer designer)
- {
- redoDropDown = new RedoDropDown(designer, this);
- Click += designer.cmdRedo.Invoke;
- }
- }
- internal class UndoRedoDropDown : ItemContainer
- {
- private bool updating;
- protected Designer designer;
- protected ListBox lbxActions;
- protected Label lblUndoRedo;
- protected ButtonItem parent;
- protected ControlContainerItem actionsHost;
- protected ControlContainerItem 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;
- }
- public override void UpdateDpiDependencies()
- {
- base.UpdateDpiDependencies();
- UpdateSizes();
- }
- private void lbxActions_MouseMove(object sender, MouseEventArgs e)
- {
- int index = lbxActions.IndexFromPoint(e.X, e.Y);
- SetSelected(index);
- }
- private void lbxActions_MouseDown(object sender, MouseEventArgs e)
- {
- int actionsCount = lbxActions.SelectedItems.Count + 1;
- parent.ClosePopup();
- 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)
- {
- }
- private void parent_PopupOpen(object sender, PopupOpenEventArgs e)
- {
- PopulateItems();
- UpdateSizes();
- SetSelected(0);
- }
- public UndoRedoDropDown(Designer designer, ButtonItem parent)
- {
- this.designer = designer;
- this.parent = parent;
- LayoutOrientation = eOrientation.Vertical;
- parent.PopupType = ePopupType.ToolBar;
- parent.SubItems.Add(this);
- parent.PopupOpen += new DotNetBarManager.PopupOpenEventHandler(parent_PopupOpen);
- lbxActions = new ListBox();
- lbxActions.Size = new Size(150, 200);
- lbxActions.BorderStyle = BorderStyle.None;
- lbxActions.SelectionMode = SelectionMode.MultiSimple;
- lbxActions.MouseMove += new MouseEventHandler(lbxActions_MouseMove);
- lbxActions.MouseDown += new MouseEventHandler(lbxActions_MouseDown);
- actionsHost = new ControlContainerItem();
- actionsHost.Control = lbxActions;
- SubItems.Add(actionsHost);
- lblUndoRedo = new Label();
- lblUndoRedo.AutoSize = false;
- lblUndoRedo.Size = new Size(150, 30);
- lblUndoRedo.TextAlign = ContentAlignment.MiddleCenter;
- lblUndoRedo.BackColor = Color.Transparent;
- labelHost = new ControlContainerItem();
- labelHost.Control = lblUndoRedo;
- SubItems.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, ButtonItem parent)
- : base(designer, parent)
- {
- }
- }
- 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, ButtonItem parent)
- : base(designer, parent)
- {
- }
- }
- }
|