| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294 |
- /*******************************************************************************
- * Copyright(c) 2014 DongkeSoft All rights reserved. / Confidential
- * 类的信息:
- * 1.程序名称:DockPaneStripBase.cs
- * 2.功能描述:类文件
- * 编辑履历:
- * 作者 日期 版本 修改内容
- * 陈晓野 2014/09/01 1.00 新建
- *******************************************************************************/
- using System;
- using System.Collections;
- using System.Collections.Generic;
- using System.Diagnostics.CodeAnalysis;
- using System.Drawing;
- using System.Drawing.Drawing2D;
- using System.Security.Permissions;
- using System.Windows.Forms;
- namespace Dongke.IBOSS.PRD.Basics.DockPanel
- {
- public abstract class DockPaneStripBase : Control
- {
- [SuppressMessage("Microsoft.Design", "CA1034:NestedTypesShouldNotBeVisible")]
- protected internal class Tab : IDisposable
- {
- private IDockContent m_content;
- public Tab(IDockContent content)
- {
- m_content = content;
- }
- ~Tab()
- {
- Dispose(false);
- }
- public IDockContent Content
- {
- get
- {
- return m_content;
- }
- }
- public Form ContentForm
- {
- get
- {
- return m_content as Form;
- }
- }
- public void Dispose()
- {
- Dispose(true);
- GC.SuppressFinalize(this);
- }
- protected virtual void Dispose(bool disposing)
- {
- }
- }
- [SuppressMessage("Microsoft.Design", "CA1034:NestedTypesShouldNotBeVisible")]
- protected sealed class TabCollection : IEnumerable<Tab>
- {
- #region IEnumerable Members
- IEnumerator<Tab> IEnumerable<Tab>.GetEnumerator()
- {
- for (int i = 0; i < Count; i++)
- yield return this[i];
- }
- IEnumerator IEnumerable.GetEnumerator()
- {
- for (int i = 0; i < Count; i++)
- yield return this[i];
- }
- #endregion
- internal TabCollection(DockPane pane)
- {
- m_dockPane = pane;
- }
- private DockPane m_dockPane;
- public DockPane DockPane
- {
- get
- {
- return m_dockPane;
- }
- }
- public int Count
- {
- get
- {
- return DockPane.DisplayingContents.Count;
- }
- }
- public Tab this[int index]
- {
- get
- {
- IDockContent content = DockPane.DisplayingContents[index];
- if (content == null)
- throw (new ArgumentOutOfRangeException("index"));
- return content.DockHandler.GetTab(DockPane.TabStripControl);
- }
- }
- public bool Contains(Tab tab)
- {
- return (IndexOf(tab) != -1);
- }
- public bool Contains(IDockContent content)
- {
- return (IndexOf(content) != -1);
- }
- public int IndexOf(Tab tab)
- {
- if (tab == null)
- return -1;
- return DockPane.DisplayingContents.IndexOf(tab.Content);
- }
- public int IndexOf(IDockContent content)
- {
- return DockPane.DisplayingContents.IndexOf(content);
- }
- }
- protected DockPaneStripBase(DockPane pane)
- {
- m_dockPane = pane;
- SetStyle(ControlStyles.OptimizedDoubleBuffer, true);
- SetStyle(ControlStyles.Selectable, false);
- AllowDrop = true;
- }
- private DockPane m_dockPane;
- protected DockPane DockPane
- {
- get
- {
- return m_dockPane;
- }
- }
- protected DockPane.AppearanceStyle Appearance
- {
- get
- {
- return DockPane.Appearance;
- }
- }
- private TabCollection m_tabs = null;
- protected TabCollection Tabs
- {
- get
- {
- if (m_tabs == null)
- m_tabs = new TabCollection(DockPane);
- return m_tabs;
- }
- }
- internal void RefreshChanges()
- {
- if (IsDisposed)
- return;
- OnRefreshChanges();
- }
- protected virtual void OnRefreshChanges()
- {
- }
- protected internal abstract int MeasureHeight();
- protected internal abstract void EnsureTabVisible(IDockContent content);
- protected int HitTest()
- {
- return HitTest(PointToClient(Control.MousePosition));
- }
- protected internal abstract int HitTest(Point point);
- protected internal abstract GraphicsPath GetOutline(int index);
- protected internal virtual Tab CreateTab(IDockContent content)
- {
- return new Tab(content);
- }
- protected override void OnMouseDown(MouseEventArgs e)
- {
- base.OnMouseDown(e);
- int index = HitTest(e.Location);
- if (index != -1)
- {
- if (e.Button == MouseButtons.Middle)
- {
- // Close the specified content.
- IDockContent content = Tabs[index].Content;
- DockPane.CloseContent(content);
- }
- else
- {
- IDockContent content = Tabs[index].Content;
- if (DockPane.ActiveContent != content)
- DockPane.ActiveContent = content;
- }
- }
- if (e.Button == MouseButtons.Left)
- {
- if (DockPane.DockPanel.AllowEndUserDocking && DockPane.AllowDockDragAndDrop && DockPane.ActiveContent.DockHandler.AllowEndUserDocking)
- DockPane.DockPanel.BeginDrag(DockPane.ActiveContent.DockHandler);
- }
- }
- protected bool HasTabPageContextMenu
- {
- get
- {
- return DockPane.HasTabPageContextMenu;
- }
- }
- protected void ShowTabPageContextMenu(Point position)
- {
- DockPane.ShowTabPageContextMenu(this, position);
- }
- protected override void OnMouseUp(MouseEventArgs e)
- {
- base.OnMouseUp(e);
- if (e.Button == MouseButtons.Right)
- ShowTabPageContextMenu(new Point(e.X, e.Y));
- }
- [SecurityPermission(SecurityAction.LinkDemand, Flags = SecurityPermissionFlag.UnmanagedCode)]
- protected override void WndProc(ref Message m)
- {
- if (m.Msg == (int)Win32.Msgs.WM_LBUTTONDBLCLK)
- {
- base.WndProc(ref m);
- int index = HitTest();
- if (DockPane.DockPanel.AllowEndUserDocking && index != -1)
- {
- IDockContent content = Tabs[index].Content;
- if (content.DockHandler.CheckDockState(!content.DockHandler.IsFloat) != DockState.Unknown)
- //content.DockHandler.IsFloat = !content.DockHandler.IsFloat;
- content.DockHandler.Close();
- }
- return;
- }
- base.WndProc(ref m);
- return;
- }
- protected override void OnDragOver(DragEventArgs drgevent)
- {
- base.OnDragOver(drgevent);
- int index = HitTest();
- if (index != -1)
- {
- IDockContent content = Tabs[index].Content;
- if (DockPane.ActiveContent != content)
- DockPane.ActiveContent = content;
- }
- }
- }
- }
|