DocumentBottomStrip.cs 7.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236
  1. using SmartCoalApplication.Base;
  2. using SmartCoalApplication.SystemLayer;
  3. using System;
  4. using System.Collections.Generic;
  5. using System.ComponentModel;
  6. using System.Drawing;
  7. using System.Windows.Forms;
  8. namespace SmartCoalApplication.Core.CustomControl
  9. {
  10. public enum DocumentBottomClickAction
  11. {
  12. Select,
  13. Close
  14. }
  15. public partial class DocumentBottomStrip : IBottomNameStrip
  16. {
  17. private List<string> documents = new List<string>();
  18. private List<Color> documentColors = new List<Color>();
  19. private List<IBottomNameStrip.Item> documentButtons = new List<IBottomNameStrip.Item>();
  20. private Dictionary<string, IBottomNameStrip.Item> dw2button = new Dictionary<string, IBottomNameStrip.Item>();
  21. private Dictionary<string, RenderArgs> thumbs = new Dictionary<string, RenderArgs>();
  22. public void ClearTextBox()
  23. {
  24. this.documents.Clear();
  25. this.documentColors.Clear();
  26. this.items.Clear();
  27. this.documentButtons.Clear();
  28. this.dw2button.Clear();
  29. QueueThumbnailUpdate(this.documents.Count + "");
  30. OnDocumentListChanged();
  31. }
  32. public int DocumentCount
  33. {
  34. get
  35. {
  36. return this.documents.Count;
  37. }
  38. }
  39. public event EventHandler DocumentListChanged;
  40. protected virtual void OnDocumentListChanged()
  41. {
  42. if (DocumentListChanged != null)
  43. {
  44. DocumentListChanged(this, EventArgs.Empty);
  45. }
  46. }
  47. public override Size GetPreferredSize(Size proposedSize)
  48. {
  49. Size itemSize = ItemSize;
  50. int preferredWidth;
  51. if (this.ItemCount == 0)
  52. {
  53. preferredWidth = 0;
  54. }
  55. else
  56. {
  57. preferredWidth = itemSize.Width * DocumentCount;
  58. }
  59. Size preferredSize = new Size(preferredWidth, itemSize.Height);
  60. return preferredSize;
  61. }
  62. public DocumentBottomStrip()
  63. {
  64. InitializeComponent();
  65. this.ShowCloseButtons = false;
  66. this.ShowCheckedColor = false;
  67. }
  68. private void InitializeComponent()
  69. {
  70. this.Name = "DocumentBottomStrip";
  71. }
  72. protected override void Dispose(bool disposing)
  73. {
  74. base.Dispose(disposing);
  75. }
  76. protected override void OnScrollArrowClicked(ArrowDirection arrowDirection)
  77. {
  78. int sign = 0;
  79. switch (arrowDirection)
  80. {
  81. case ArrowDirection.Left:
  82. sign = -1;
  83. break;
  84. case ArrowDirection.Right:
  85. sign = +1;
  86. break;
  87. }
  88. int delta = ItemSize.Width;
  89. ScrollOffset += sign * delta;
  90. base.OnScrollArrowClicked(arrowDirection);
  91. }
  92. protected override void OnItemClicked(Item item, ItemPart itemPart, MouseButtons mouseButtons)
  93. {
  94. string dw = item.Tag as string;
  95. if (dw != null)
  96. {
  97. switch (itemPart)
  98. {
  99. case ItemPart.None:
  100. // do nothing
  101. break;
  102. case ItemPart.CloseButton:
  103. if (mouseButtons == MouseButtons.Left)
  104. {
  105. OnDocumentClicked(dw, DocumentBottomClickAction.Close);
  106. }
  107. break;
  108. case ItemPart.Image:
  109. if (mouseButtons == MouseButtons.Left)
  110. {
  111. SelectTextBox(dw);
  112. //SelectedDocument = dw;
  113. }
  114. else if (mouseButtons == MouseButtons.Right)
  115. {
  116. // TODO ZYH 预留右键菜单
  117. }
  118. break;
  119. default:
  120. throw new InvalidEnumArgumentException();
  121. }
  122. }
  123. base.OnItemClicked(item, itemPart, mouseButtons);
  124. }
  125. public event EventHandler<EventArgs<Pair<string, DocumentBottomClickAction>>> DocumentClicked;
  126. protected virtual void OnDocumentClicked(string dw, DocumentBottomClickAction action)
  127. {
  128. if (DocumentClicked != null)
  129. {
  130. DocumentClicked(this, new EventArgs<Pair<string, DocumentBottomClickAction>>(
  131. Pair.Create(dw, action)));
  132. }
  133. }
  134. public void AddTextBox(string addMe, Color color, bool check)
  135. {
  136. this.documents.Add(addMe);
  137. this.documentColors.Add(color);
  138. IBottomNameStrip.Item docButton = new IBottomNameStrip.Item();
  139. docButton.Image = null;
  140. docButton.Tag = this.documents.Count + "";
  141. docButton.Checked = check;
  142. docButton.NColor = color;
  143. AddItem(docButton);
  144. this.documentButtons.Add(docButton);
  145. if (!this.dw2button.ContainsKey(this.documents.Count + ""))
  146. {
  147. this.dw2button.Add(this.documents.Count + "", docButton);
  148. }
  149. QueueThumbnailUpdate(this.documents.Count + "");
  150. OnDocumentListChanged();
  151. }
  152. public void RemoveTextBox(string removeMe)
  153. {
  154. OnDocumentListChanged();
  155. }
  156. protected override void OnLayout(LayoutEventArgs levent)
  157. {
  158. base.OnLayout(levent);
  159. }
  160. public void SelectTextBox(string selectMe)
  161. {
  162. UI.SuspendControlPainting(this);
  163. foreach (IBottomNameStrip.Item docItem in this.documentButtons)
  164. {
  165. if ((docItem.Tag as string) == selectMe)
  166. {
  167. EnsureItemFullyVisible(docItem);
  168. docItem.Checked = !docItem.Checked;
  169. if (this.AllowMultiChoise)
  170. {
  171. break;
  172. }
  173. }
  174. else if (!this.AllowMultiChoise)
  175. {
  176. docItem.Checked = false;
  177. }
  178. }
  179. UI.ResumeControlPainting(this);
  180. Invalidate(true);
  181. }
  182. private void OnThumbnailUpdated(string dw)
  183. {
  184. if (this.dw2button.ContainsKey(dw))
  185. {
  186. IBottomNameStrip.Item docButton = this.dw2button[dw];
  187. //RenderArgs docRA = this.thumbs[dw];
  188. docButton.Name = this.documents[int.Parse(dw) - 1]/*dw*/;//.GetFriendlyName();
  189. docButton.NColor = this.documentColors[int.Parse(dw) - 1];
  190. //docButton.Image = docRA.Bitmap;
  191. docButton.Update();
  192. }
  193. }
  194. public void QueueThumbnailUpdate(string dw)
  195. {
  196. OnThumbnailUpdated(dw);
  197. }
  198. }
  199. }