Free cookie consent management tool by TermsFeed Policy Generator

source: trunk/sources/HeuristicLab.ExtLibs/HeuristicLab.WinFormsUI/2.3.1/WinFormsUI-2.3.1/Docking/DockPaneStripBase.cs @ 6675

Last change on this file since 6675 was 4068, checked in by swagner, 14 years ago

Sorted usings and removed unused usings in entire solution (#1094)

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