[2134] | 1 | using System;
|
---|
| 2 | using System.Windows.Forms;
|
---|
| 3 | using System.Drawing;
|
---|
| 4 | using System.Drawing.Drawing2D;
|
---|
| 5 | using System.Collections;
|
---|
| 6 | using System.Collections.Generic;
|
---|
| 7 | using System.Security.Permissions;
|
---|
| 8 | using System.Diagnostics.CodeAnalysis;
|
---|
| 9 |
|
---|
| 10 | namespace WeifenLuo.WinFormsUI.Docking
|
---|
| 11 | {
|
---|
| 12 | public abstract class DockPaneStripBase : Control
|
---|
| 13 | {
|
---|
| 14 | [SuppressMessage("Microsoft.Design", "CA1034:NestedTypesShouldNotBeVisible")]
|
---|
| 15 | protected internal class Tab : IDisposable
|
---|
| 16 | {
|
---|
| 17 | private IDockContent m_content;
|
---|
| 18 |
|
---|
| 19 | public Tab(IDockContent content)
|
---|
| 20 | {
|
---|
| 21 | m_content = content;
|
---|
| 22 | }
|
---|
| 23 |
|
---|
| 24 | ~Tab()
|
---|
| 25 | {
|
---|
| 26 | Dispose(false);
|
---|
| 27 | }
|
---|
| 28 |
|
---|
| 29 | public IDockContent Content
|
---|
| 30 | {
|
---|
| 31 | get { return m_content; }
|
---|
| 32 | }
|
---|
| 33 |
|
---|
| 34 | public Form ContentForm
|
---|
| 35 | {
|
---|
| 36 | get { return m_content as Form; }
|
---|
| 37 | }
|
---|
| 38 |
|
---|
| 39 | public void Dispose()
|
---|
| 40 | {
|
---|
| 41 | Dispose(true);
|
---|
| 42 | GC.SuppressFinalize(this);
|
---|
| 43 | }
|
---|
| 44 |
|
---|
| 45 | protected virtual void Dispose(bool disposing)
|
---|
| 46 | {
|
---|
| 47 | }
|
---|
| 48 | }
|
---|
| 49 |
|
---|
| 50 | [SuppressMessage("Microsoft.Design", "CA1034:NestedTypesShouldNotBeVisible")]
|
---|
| 51 | protected sealed class TabCollection : IEnumerable<Tab>
|
---|
| 52 | {
|
---|
| 53 | #region IEnumerable Members
|
---|
| 54 | IEnumerator<Tab> IEnumerable<Tab>.GetEnumerator()
|
---|
| 55 | {
|
---|
| 56 | for (int i = 0; i < Count; i++)
|
---|
| 57 | yield return this[i];
|
---|
| 58 | }
|
---|
| 59 |
|
---|
| 60 | IEnumerator IEnumerable.GetEnumerator()
|
---|
| 61 | {
|
---|
| 62 | for (int i = 0; i < Count; i++)
|
---|
| 63 | yield return this[i];
|
---|
| 64 | }
|
---|
| 65 | #endregion
|
---|
| 66 |
|
---|
| 67 | internal TabCollection(DockPane pane)
|
---|
| 68 | {
|
---|
| 69 | m_dockPane = pane;
|
---|
| 70 | }
|
---|
| 71 |
|
---|
| 72 | private DockPane m_dockPane;
|
---|
| 73 | public DockPane DockPane
|
---|
| 74 | {
|
---|
| 75 | get { return m_dockPane; }
|
---|
| 76 | }
|
---|
| 77 |
|
---|
| 78 | public int Count
|
---|
| 79 | {
|
---|
| 80 | get { return DockPane.DisplayingContents.Count; }
|
---|
| 81 | }
|
---|
| 82 |
|
---|
| 83 | public Tab this[int index]
|
---|
| 84 | {
|
---|
| 85 | get
|
---|
| 86 | {
|
---|
| 87 | IDockContent content = DockPane.DisplayingContents[index];
|
---|
| 88 | if (content == null)
|
---|
| 89 | throw (new ArgumentOutOfRangeException("index"));
|
---|
| 90 | return content.DockHandler.GetTab(DockPane.TabStripControl);
|
---|
| 91 | }
|
---|
| 92 | }
|
---|
| 93 |
|
---|
| 94 | public bool Contains(Tab tab)
|
---|
| 95 | {
|
---|
| 96 | return (IndexOf(tab) != -1);
|
---|
| 97 | }
|
---|
| 98 |
|
---|
| 99 | public bool Contains(IDockContent content)
|
---|
| 100 | {
|
---|
| 101 | return (IndexOf(content) != -1);
|
---|
| 102 | }
|
---|
| 103 |
|
---|
| 104 | public int IndexOf(Tab tab)
|
---|
| 105 | {
|
---|
| 106 | if (tab == null)
|
---|
| 107 | return -1;
|
---|
| 108 |
|
---|
| 109 | return DockPane.DisplayingContents.IndexOf(tab.Content);
|
---|
| 110 | }
|
---|
| 111 |
|
---|
| 112 | public int IndexOf(IDockContent content)
|
---|
| 113 | {
|
---|
| 114 | return DockPane.DisplayingContents.IndexOf(content);
|
---|
| 115 | }
|
---|
| 116 | }
|
---|
| 117 |
|
---|
| 118 | protected DockPaneStripBase(DockPane pane)
|
---|
| 119 | {
|
---|
| 120 | m_dockPane = pane;
|
---|
| 121 |
|
---|
| 122 | SetStyle(ControlStyles.OptimizedDoubleBuffer, true);
|
---|
| 123 | SetStyle(ControlStyles.Selectable, false);
|
---|
| 124 | AllowDrop = true;
|
---|
| 125 | }
|
---|
| 126 |
|
---|
| 127 | private DockPane m_dockPane;
|
---|
| 128 | protected DockPane DockPane
|
---|
| 129 | {
|
---|
| 130 | get { return m_dockPane; }
|
---|
| 131 | }
|
---|
| 132 |
|
---|
| 133 | protected DockPane.AppearanceStyle Appearance
|
---|
| 134 | {
|
---|
| 135 | get { return DockPane.Appearance; }
|
---|
| 136 | }
|
---|
| 137 |
|
---|
| 138 | private TabCollection m_tabs = null;
|
---|
| 139 | protected TabCollection Tabs
|
---|
| 140 | {
|
---|
| 141 | get
|
---|
| 142 | {
|
---|
| 143 | if (m_tabs == null)
|
---|
| 144 | m_tabs = new TabCollection(DockPane);
|
---|
| 145 |
|
---|
| 146 | return m_tabs;
|
---|
| 147 | }
|
---|
| 148 | }
|
---|
| 149 |
|
---|
| 150 | internal void RefreshChanges()
|
---|
| 151 | {
|
---|
| 152 | if (IsDisposed)
|
---|
| 153 | return;
|
---|
| 154 |
|
---|
| 155 | OnRefreshChanges();
|
---|
| 156 | }
|
---|
| 157 |
|
---|
| 158 | protected virtual void OnRefreshChanges()
|
---|
| 159 | {
|
---|
| 160 | }
|
---|
| 161 |
|
---|
| 162 | protected internal abstract int MeasureHeight();
|
---|
| 163 |
|
---|
| 164 | protected internal abstract void EnsureTabVisible(IDockContent content);
|
---|
| 165 |
|
---|
| 166 | protected int HitTest()
|
---|
| 167 | {
|
---|
| 168 | return HitTest(PointToClient(Control.MousePosition));
|
---|
| 169 | }
|
---|
| 170 |
|
---|
| 171 | protected internal abstract int HitTest(Point point);
|
---|
| 172 |
|
---|
| 173 | protected internal abstract GraphicsPath GetOutline(int index);
|
---|
| 174 |
|
---|
| 175 | protected internal virtual Tab CreateTab(IDockContent content)
|
---|
| 176 | {
|
---|
| 177 | return new Tab(content);
|
---|
| 178 | }
|
---|
| 179 |
|
---|
| 180 | protected override void OnMouseDown(MouseEventArgs e)
|
---|
| 181 | {
|
---|
| 182 | base.OnMouseDown(e);
|
---|
| 183 |
|
---|
| 184 | int index = HitTest();
|
---|
| 185 | if (index != -1)
|
---|
| 186 | {
|
---|
| 187 | IDockContent content = Tabs[index].Content;
|
---|
| 188 | if (DockPane.ActiveContent != content)
|
---|
| 189 | DockPane.ActiveContent = content;
|
---|
| 190 | }
|
---|
| 191 |
|
---|
| 192 | if (e.Button == MouseButtons.Left)
|
---|
| 193 | {
|
---|
| 194 | if (DockPane.DockPanel.AllowEndUserDocking && DockPane.AllowDockDragAndDrop && DockPane.ActiveContent.DockHandler.AllowEndUserDocking)
|
---|
| 195 | DockPane.DockPanel.BeginDrag(DockPane.ActiveContent.DockHandler);
|
---|
| 196 | }
|
---|
| 197 | }
|
---|
| 198 |
|
---|
| 199 | protected bool HasTabPageContextMenu
|
---|
| 200 | {
|
---|
| 201 | get { return DockPane.HasTabPageContextMenu; }
|
---|
| 202 | }
|
---|
| 203 |
|
---|
| 204 | protected void ShowTabPageContextMenu(Point position)
|
---|
| 205 | {
|
---|
| 206 | DockPane.ShowTabPageContextMenu(this, position);
|
---|
| 207 | }
|
---|
| 208 |
|
---|
| 209 | protected override void OnMouseUp(MouseEventArgs e)
|
---|
| 210 | {
|
---|
| 211 | base.OnMouseUp(e);
|
---|
| 212 |
|
---|
| 213 | if (e.Button == MouseButtons.Right)
|
---|
| 214 | ShowTabPageContextMenu(new Point(e.X, e.Y));
|
---|
| 215 | }
|
---|
| 216 |
|
---|
| 217 | [SecurityPermission(SecurityAction.LinkDemand, Flags = SecurityPermissionFlag.UnmanagedCode)]
|
---|
| 218 | protected override void WndProc(ref Message m)
|
---|
| 219 | {
|
---|
| 220 | if (m.Msg == (int)Win32.Msgs.WM_LBUTTONDBLCLK)
|
---|
| 221 | {
|
---|
| 222 | base.WndProc(ref m);
|
---|
| 223 |
|
---|
| 224 | int index = HitTest();
|
---|
| 225 | if (DockPane.DockPanel.AllowEndUserDocking && index != -1)
|
---|
| 226 | {
|
---|
| 227 | IDockContent content = Tabs[index].Content;
|
---|
| 228 | if (content.DockHandler.CheckDockState(!content.DockHandler.IsFloat) != DockState.Unknown)
|
---|
| 229 | content.DockHandler.IsFloat = !content.DockHandler.IsFloat;
|
---|
| 230 | }
|
---|
| 231 |
|
---|
| 232 | return;
|
---|
| 233 | }
|
---|
| 234 |
|
---|
| 235 | base.WndProc(ref m);
|
---|
| 236 | return;
|
---|
| 237 | }
|
---|
| 238 |
|
---|
| 239 | protected override void OnDragOver(DragEventArgs drgevent)
|
---|
| 240 | {
|
---|
| 241 | base.OnDragOver(drgevent);
|
---|
| 242 |
|
---|
| 243 | int index = HitTest();
|
---|
| 244 | if (index != -1)
|
---|
| 245 | {
|
---|
| 246 | IDockContent content = Tabs[index].Content;
|
---|
| 247 | if (DockPane.ActiveContent != content)
|
---|
| 248 | DockPane.ActiveContent = content;
|
---|
| 249 | }
|
---|
| 250 | }
|
---|
| 251 | }
|
---|
| 252 | }
|
---|