UndoRedoDropDown.cs 8.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262
  1. using System;
  2. using System.ComponentModel;
  3. using System.Windows.Forms;
  4. using System.Drawing;
  5. using FastReport.Utils;
  6. #if !MONO
  7. using FastReport.DevComponents.DotNetBar;
  8. #endif
  9. namespace FastReport.Design.Toolbars
  10. {
  11. #if !MONO
  12. internal class UndoRedoDropDown : ItemContainer
  13. #else
  14. internal class UndoRedoDropDown : ToolStripDropDown
  15. #endif
  16. {
  17. private bool updating;
  18. protected Designer designer;
  19. protected ListBox lbxActions;
  20. protected Label lblUndoRedo;
  21. #if !MONO
  22. protected ButtonItem parent;
  23. protected ControlContainerItem actionsHost;
  24. protected ControlContainerItem labelHost;
  25. #else
  26. protected ToolbarBase toolbar;
  27. protected ToolStripControlHost actionsHost;
  28. protected ToolStripControlHost labelHost;
  29. #endif
  30. private void SetSelected(int index)
  31. {
  32. if (updating)
  33. return;
  34. updating = true;
  35. int saveTop = lbxActions.TopIndex;
  36. lbxActions.BeginUpdate();
  37. lbxActions.SelectedIndices.Clear();
  38. if (lbxActions.Items.Count > 0)
  39. {
  40. for (int i = index; i >= 0; i--)
  41. lbxActions.SelectedIndices.Add(i);
  42. }
  43. lbxActions.TopIndex = saveTop;
  44. lbxActions.EndUpdate();
  45. UpdateLabel();
  46. updating = false;
  47. }
  48. #if !MONO
  49. public override void UpdateDpiDependencies()
  50. {
  51. base.UpdateDpiDependencies();
  52. lbxActions.Size = designer.LogicalToDevice(new Size(150, 200));
  53. lblUndoRedo.Size = designer.LogicalToDevice(new Size(150, 30));
  54. UpdateSizes();
  55. }
  56. #endif
  57. private void lbxActions_MouseMove(object sender, MouseEventArgs e)
  58. {
  59. int index = lbxActions.IndexFromPoint(e.X, e.Y);
  60. SetSelected(index);
  61. }
  62. private void lbxActions_MouseDown(object sender, MouseEventArgs e)
  63. {
  64. int actionsCount = lbxActions.SelectedItems.Count + 1;
  65. #if !MONO
  66. parent.ClosePopup();
  67. #else
  68. Close(ToolStripDropDownCloseReason.ItemClicked);
  69. #endif
  70. DoUndoRedo(actionsCount);
  71. }
  72. private void UpdateSizes()
  73. {
  74. float maxWidth = DrawUtils.MeasureString(String.Format(Res.Get("Designer,UndoRedo,UndoN"), 100), lblUndoRedo.Font).Width + 10;
  75. for (int i = 0; i < lbxActions.Items.Count; i++)
  76. {
  77. string s = (string)lbxActions.Items[i];
  78. float width = DrawUtils.MeasureString(s, lbxActions.Font).Width;
  79. if (width > maxWidth)
  80. maxWidth = width;
  81. }
  82. float maxHeight = (lbxActions.Items.Count > 10 ? 10 : lbxActions.Items.Count) * lbxActions.ItemHeight;
  83. actionsHost.Size = new Size((int)maxWidth + 10, (int)maxHeight);
  84. lblUndoRedo.Size = new Size((int)maxWidth + 10, designer.LogicalToDevice(20));
  85. }
  86. protected virtual void PopulateItems()
  87. {
  88. }
  89. protected virtual void UpdateLabel()
  90. {
  91. }
  92. protected virtual void DoUndoRedo(int actionsCount)
  93. {
  94. }
  95. #if !MONO
  96. private void parent_PopupOpen(object sender, PopupOpenEventArgs e)
  97. {
  98. #else
  99. protected override void OnOpening(CancelEventArgs e)
  100. {
  101. base.OnOpening(e);
  102. #endif
  103. PopulateItems();
  104. UpdateSizes();
  105. SetSelected(0);
  106. }
  107. #if !MONO
  108. public UndoRedoDropDown(Designer designer, ButtonItem parent)
  109. #else
  110. public UndoRedoDropDown(Designer designer, ToolbarBase toolbar)
  111. : base()
  112. #endif
  113. {
  114. this.designer = designer;
  115. #if !MONO
  116. this.parent = parent;
  117. LayoutOrientation = eOrientation.Vertical;
  118. parent.PopupType = ePopupType.ToolBar;
  119. parent.SubItems.Add(this);
  120. parent.PopupOpen += new DotNetBarManager.PopupOpenEventHandler(parent_PopupOpen);
  121. lbxActions = new ListBox();
  122. lbxActions.Size = new Size(150, 200);
  123. lbxActions.BorderStyle = BorderStyle.None;
  124. lbxActions.SelectionMode = SelectionMode.MultiSimple;
  125. lbxActions.MouseMove += new MouseEventHandler(lbxActions_MouseMove);
  126. lbxActions.MouseDown += new MouseEventHandler(lbxActions_MouseDown);
  127. actionsHost = new ControlContainerItem();
  128. actionsHost.Control = lbxActions;
  129. SubItems.Add(actionsHost);
  130. lblUndoRedo = new Label();
  131. lblUndoRedo.AutoSize = false;
  132. lblUndoRedo.Size = new Size(150, 30);
  133. lblUndoRedo.TextAlign = ContentAlignment.MiddleCenter;
  134. lblUndoRedo.BackColor = Color.Transparent;
  135. labelHost = new ControlContainerItem();
  136. labelHost.Control = lblUndoRedo;
  137. SubItems.Add(labelHost);
  138. #else
  139. this.toolbar = toolbar;
  140. Renderer = toolbar.Renderer;
  141. Padding = new Padding(1);
  142. Font = toolbar.Font;
  143. lbxActions = new ListBox();
  144. lbxActions.Dock = DockStyle.Fill;
  145. lbxActions.BorderStyle = BorderStyle.None;
  146. lbxActions.SelectionMode = SelectionMode.MultiSimple;
  147. lbxActions.MouseMove += new MouseEventHandler(lbxActions_MouseMove);
  148. lbxActions.MouseDown += new MouseEventHandler(lbxActions_MouseDown);
  149. actionsHost = new ToolStripControlHost(lbxActions);
  150. actionsHost.AutoSize = false;
  151. actionsHost.Size = new Size(150, 250);
  152. Items.Add(actionsHost);
  153. lblUndoRedo = new Label();
  154. lblUndoRedo.Dock = DockStyle.Fill;
  155. lblUndoRedo.AutoSize = false;
  156. lblUndoRedo.TextAlign = ContentAlignment.MiddleCenter;
  157. lblUndoRedo.Text = "test";
  158. lblUndoRedo.BackColor = Color.Transparent;
  159. labelHost = new ToolStripControlHost(lblUndoRedo);
  160. labelHost.AutoSize = false;
  161. labelHost.Size = new Size(100, 30);
  162. Items.Add(labelHost);
  163. #endif
  164. }
  165. }
  166. internal class UndoDropDown : UndoRedoDropDown
  167. {
  168. protected override void PopulateItems()
  169. {
  170. lbxActions.Items.Clear();
  171. if (designer.ActiveReport != null)
  172. {
  173. string[] undoNames = designer.ActiveReportTab.UndoRedo.UndoNames;
  174. foreach (string s in undoNames)
  175. {
  176. lbxActions.Items.Add(s);
  177. }
  178. }
  179. }
  180. protected override void UpdateLabel()
  181. {
  182. lblUndoRedo.Text = String.Format(Res.Get("Designer,UndoRedo,UndoN"), lbxActions.SelectedItems.Count);
  183. }
  184. protected override void DoUndoRedo(int actionsCount)
  185. {
  186. designer.cmdUndo.Undo(actionsCount);
  187. }
  188. #if !MONO
  189. public UndoDropDown(Designer designer, ButtonItem parent)
  190. : base(designer, parent)
  191. #else
  192. public UndoDropDown(Designer designer, ToolbarBase toolbar)
  193. : base(designer, toolbar)
  194. #endif
  195. {
  196. }
  197. }
  198. internal class RedoDropDown : UndoRedoDropDown
  199. {
  200. protected override void PopulateItems()
  201. {
  202. lbxActions.Items.Clear();
  203. if (designer.ActiveReport != null)
  204. {
  205. string[] undoNames = designer.ActiveReportTab.UndoRedo.RedoNames;
  206. foreach (string s in undoNames)
  207. {
  208. lbxActions.Items.Add(s);
  209. }
  210. }
  211. }
  212. protected override void UpdateLabel()
  213. {
  214. lblUndoRedo.Text = String.Format(Res.Get("Designer,UndoRedo,RedoN"), lbxActions.SelectedItems.Count);
  215. }
  216. protected override void DoUndoRedo(int actionsCount)
  217. {
  218. designer.cmdRedo.Redo(actionsCount);
  219. }
  220. #if !MONO
  221. public RedoDropDown(Designer designer, ButtonItem parent)
  222. : base(designer, parent)
  223. #else
  224. public RedoDropDown(Designer designer, ToolbarBase toolbar)
  225. : base(designer, toolbar)
  226. #endif
  227. {
  228. }
  229. }
  230. }