using PaintDotNet.SystemLayer; using System; using System.Collections.Generic; using System.ComponentModel; using System.Drawing; using System.Windows.Forms; namespace PaintDotNet.CustomControl { public enum DocumentBottomClickAction { Select, Close } public partial class DocumentBottomStrip : IBottomNameStrip { private List documents = new List(); private List documentColors = new List(); private List documentButtons = new List(); private Dictionary dw2button = new Dictionary(); private Dictionary thumbs = new Dictionary(); public void ClearTextBox() { this.documents.Clear(); this.documentColors.Clear(); this.items.Clear(); this.documentButtons.Clear(); this.dw2button.Clear(); QueueThumbnailUpdate(this.documents.Count + ""); OnDocumentListChanged(); } public int DocumentCount { get { return this.documents.Count; } } public event EventHandler DocumentListChanged; protected virtual void OnDocumentListChanged() { if (DocumentListChanged != null) { DocumentListChanged(this, EventArgs.Empty); } } public override Size GetPreferredSize(Size proposedSize) { Size itemSize = ItemSize; int preferredWidth; if (this.ItemCount == 0) { preferredWidth = 0; } else { preferredWidth = itemSize.Width * DocumentCount; } Size preferredSize = new Size(preferredWidth, itemSize.Height); return preferredSize; } public DocumentBottomStrip() { InitializeComponent(); this.ShowCloseButtons = false; this.ShowCheckedColor = false; } private void InitializeComponent() { this.Name = "DocumentBottomStrip"; } protected override void Dispose(bool disposing) { base.Dispose(disposing); } protected override void OnScrollArrowClicked(ArrowDirection arrowDirection) { int sign = 0; switch (arrowDirection) { case ArrowDirection.Left: sign = -1; break; case ArrowDirection.Right: sign = +1; break; } int delta = ItemSize.Width; ScrollOffset += sign * delta; base.OnScrollArrowClicked(arrowDirection); } protected override void OnItemClicked(Item item, ItemPart itemPart, MouseButtons mouseButtons) { string dw = item.Tag as string; if (dw != null) { switch (itemPart) { case ItemPart.None: // do nothing break; case ItemPart.CloseButton: if (mouseButtons == MouseButtons.Left) { OnDocumentClicked(dw, DocumentBottomClickAction.Close); } break; case ItemPart.Image: if (mouseButtons == MouseButtons.Left) { SelectTextBox(dw); //SelectedDocument = dw; } else if (mouseButtons == MouseButtons.Right) { // TODO ZYH 预留右键菜单 } break; default: throw new InvalidEnumArgumentException(); } } base.OnItemClicked(item, itemPart, mouseButtons); } public event EventHandler>> DocumentClicked; protected virtual void OnDocumentClicked(string dw, DocumentBottomClickAction action) { if (DocumentClicked != null) { DocumentClicked(this, new EventArgs>( Pair.Create(dw, action))); } } public void AddTextBox(string addMe, Color color, bool check) { this.documents.Add(addMe); this.documentColors.Add(color); IBottomNameStrip.Item docButton = new IBottomNameStrip.Item(); docButton.Image = null; docButton.Tag = this.documents.Count + ""; docButton.Checked = check; docButton.NColor = color; AddItem(docButton); this.documentButtons.Add(docButton); if (!this.dw2button.ContainsKey(this.documents.Count + "")) { this.dw2button.Add(this.documents.Count + "", docButton); } QueueThumbnailUpdate(this.documents.Count + ""); OnDocumentListChanged(); } public void RemoveTextBox(string removeMe) { OnDocumentListChanged(); } protected override void OnLayout(LayoutEventArgs levent) { base.OnLayout(levent); } public void SelectTextBox(string selectMe) { UI.SuspendControlPainting(this); foreach (IBottomNameStrip.Item docItem in this.documentButtons) { if ((docItem.Tag as string) == selectMe) { EnsureItemFullyVisible(docItem); docItem.Checked = !docItem.Checked; if (this.AllowMultiChoise) { break; } } else if (!this.AllowMultiChoise) { docItem.Checked = false; } } UI.ResumeControlPainting(this); Invalidate(true); } private void OnThumbnailUpdated(string dw) { if (this.dw2button.ContainsKey(dw)) { IBottomNameStrip.Item docButton = this.dw2button[dw]; //RenderArgs docRA = this.thumbs[dw]; docButton.Name = this.documents[int.Parse(dw) - 1]/*dw*/;//.GetFriendlyName(); docButton.NColor = this.documentColors[int.Parse(dw) - 1]; //docButton.Image = docRA.Bitmap; docButton.Update(); } } public void QueueThumbnailUpdate(string dw) { OnThumbnailUpdated(dw); } } }