123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235 |
- 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<string> documents = new List<string>();
- private List<Color> documentColors = new List<Color>();
- private List<IBottomNameStrip.Item> documentButtons = new List<IBottomNameStrip.Item>();
- private Dictionary<string, IBottomNameStrip.Item> dw2button = new Dictionary<string, IBottomNameStrip.Item>();
- private Dictionary<string, RenderArgs> thumbs = new Dictionary<string, RenderArgs>();
- 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<EventArgs<Pair<string, DocumentBottomClickAction>>> DocumentClicked;
- protected virtual void OnDocumentClicked(string dw, DocumentBottomClickAction action)
- {
- if (DocumentClicked != null)
- {
- DocumentClicked(this, new EventArgs<Pair<string, DocumentBottomClickAction>>(
- 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);
- }
- }
- }
|