Free cookie consent management tool by TermsFeed Policy Generator

source: trunk/sources/HeuristicLab.ExtLibs/HeuristicLab.WinFormsUI/2.7.0/WinFormsUI-2.7.0/Docking/DockPaneStripBase.cs @ 8616

Last change on this file since 8616 was 8616, checked in by mkommend, 12 years ago

#1939: Added DockPanelSuite 2.7.0 to ExtLibs.

File size: 7.1 KB
Line 
1using System;
2using System.Windows.Forms;
3using System.Drawing;
4using System.Drawing.Drawing2D;
5using System.Collections;
6using System.Collections.Generic;
7using System.Security.Permissions;
8using System.Diagnostics.CodeAnalysis;
9
10namespace 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(e.Location);
185
186            if (index != -1)
187            {
188                if (e.Button == MouseButtons.Middle)
189                {
190                    // Close the specified content.
191                    IDockContent content = Tabs[index].Content;
192                    DockPane.CloseContent(content);
193                }
194                else
195                {
196                    IDockContent content = Tabs[index].Content;
197                    if (DockPane.ActiveContent != content)
198                        DockPane.ActiveContent = content;
199                }
200            }
201
202            if (e.Button == MouseButtons.Left)
203            {
204                if (DockPane.DockPanel.AllowEndUserDocking && DockPane.AllowDockDragAndDrop && DockPane.ActiveContent.DockHandler.AllowEndUserDocking)
205                    DockPane.DockPanel.BeginDrag(DockPane.ActiveContent.DockHandler);
206            }
207        }
208
209        protected bool HasTabPageContextMenu
210        {
211            get { return DockPane.HasTabPageContextMenu; }
212        }
213
214        protected void ShowTabPageContextMenu(Point position)
215        {
216            DockPane.ShowTabPageContextMenu(this, position);
217        }
218
219        protected override void OnMouseUp(MouseEventArgs e)
220        {
221            base.OnMouseUp(e);
222
223            if (e.Button == MouseButtons.Right)
224                ShowTabPageContextMenu(new Point(e.X, e.Y));
225        }
226
227        [SecurityPermission(SecurityAction.LinkDemand, Flags = SecurityPermissionFlag.UnmanagedCode)]
228    protected override void WndProc(ref Message m)
229    {
230      if (m.Msg == (int)Win32.Msgs.WM_LBUTTONDBLCLK)
231      {
232        base.WndProc(ref m);
233
234        int index = HitTest();
235        if (DockPane.DockPanel.AllowEndUserDocking && index != -1)
236        {
237          IDockContent content = Tabs[index].Content;
238                    if (content.DockHandler.CheckDockState(!content.DockHandler.IsFloat) != DockState.Unknown)
239              content.DockHandler.IsFloat = !content.DockHandler.IsFloat;
240        }
241
242        return;
243      }
244
245      base.WndProc(ref m);
246      return;
247    }
248
249        protected override void OnDragOver(DragEventArgs drgevent)
250        {
251            base.OnDragOver(drgevent);
252
253            int index = HitTest();
254            if (index != -1)
255            {
256                IDockContent content = Tabs[index].Content;
257                if (DockPane.ActiveContent != content)
258                    DockPane.ActiveContent = content;
259            }
260        }
261  }
262}
Note: See TracBrowser for help on using the repository browser.