1 | using System;
|
---|
2 | using System.Windows.Forms;
|
---|
3 | using System.Drawing;
|
---|
4 | using System.Runtime.InteropServices;
|
---|
5 | using System.ComponentModel;
|
---|
6 |
|
---|
7 | namespace WeifenLuo.WinFormsUI.Docking
|
---|
8 | {
|
---|
9 | [ToolboxItem(false)]
|
---|
10 | public partial class DockWindow : Panel, INestedPanesContainer, ISplitterDragSource
|
---|
11 | {
|
---|
12 | private DockPanel m_dockPanel;
|
---|
13 | private DockState m_dockState;
|
---|
14 | private SplitterControl m_splitter;
|
---|
15 | private NestedPaneCollection m_nestedPanes;
|
---|
16 |
|
---|
17 | internal DockWindow(DockPanel dockPanel, DockState dockState)
|
---|
18 | {
|
---|
19 | m_nestedPanes = new NestedPaneCollection(this);
|
---|
20 | m_dockPanel = dockPanel;
|
---|
21 | m_dockState = dockState;
|
---|
22 | Visible = false;
|
---|
23 |
|
---|
24 | SuspendLayout();
|
---|
25 |
|
---|
26 | if (DockState == DockState.DockLeft || DockState == DockState.DockRight ||
|
---|
27 | DockState == DockState.DockTop || DockState == DockState.DockBottom)
|
---|
28 | {
|
---|
29 | m_splitter = new SplitterControl();
|
---|
30 | Controls.Add(m_splitter);
|
---|
31 | }
|
---|
32 |
|
---|
33 | if (DockState == DockState.DockLeft)
|
---|
34 | {
|
---|
35 | Dock = DockStyle.Left;
|
---|
36 | m_splitter.Dock = DockStyle.Right;
|
---|
37 | }
|
---|
38 | else if (DockState == DockState.DockRight)
|
---|
39 | {
|
---|
40 | Dock = DockStyle.Right;
|
---|
41 | m_splitter.Dock = DockStyle.Left;
|
---|
42 | }
|
---|
43 | else if (DockState == DockState.DockTop)
|
---|
44 | {
|
---|
45 | Dock = DockStyle.Top;
|
---|
46 | m_splitter.Dock = DockStyle.Bottom;
|
---|
47 | }
|
---|
48 | else if (DockState == DockState.DockBottom)
|
---|
49 | {
|
---|
50 | Dock = DockStyle.Bottom;
|
---|
51 | m_splitter.Dock = DockStyle.Top;
|
---|
52 | }
|
---|
53 | else if (DockState == DockState.Document)
|
---|
54 | {
|
---|
55 | Dock = DockStyle.Fill;
|
---|
56 | }
|
---|
57 |
|
---|
58 | ResumeLayout();
|
---|
59 | }
|
---|
60 |
|
---|
61 | public VisibleNestedPaneCollection VisibleNestedPanes
|
---|
62 | {
|
---|
63 | get { return NestedPanes.VisibleNestedPanes; }
|
---|
64 | }
|
---|
65 |
|
---|
66 | public NestedPaneCollection NestedPanes
|
---|
67 | {
|
---|
68 | get { return m_nestedPanes; }
|
---|
69 | }
|
---|
70 |
|
---|
71 | public DockPanel DockPanel
|
---|
72 | {
|
---|
73 | get { return m_dockPanel; }
|
---|
74 | }
|
---|
75 |
|
---|
76 | public DockState DockState
|
---|
77 | {
|
---|
78 | get { return m_dockState; }
|
---|
79 | }
|
---|
80 |
|
---|
81 | public bool IsFloat
|
---|
82 | {
|
---|
83 | get { return DockState == DockState.Float; }
|
---|
84 | }
|
---|
85 |
|
---|
86 | internal DockPane DefaultPane
|
---|
87 | {
|
---|
88 | get { return VisibleNestedPanes.Count == 0 ? null : VisibleNestedPanes[0]; }
|
---|
89 | }
|
---|
90 |
|
---|
91 | public virtual Rectangle DisplayingRectangle
|
---|
92 | {
|
---|
93 | get
|
---|
94 | {
|
---|
95 | Rectangle rect = ClientRectangle;
|
---|
96 | // if DockWindow is document, exclude the border
|
---|
97 | if (DockState == DockState.Document)
|
---|
98 | {
|
---|
99 | rect.X += 1;
|
---|
100 | rect.Y += 1;
|
---|
101 | rect.Width -= 2;
|
---|
102 | rect.Height -= 2;
|
---|
103 | }
|
---|
104 | // exclude the splitter
|
---|
105 | else if (DockState == DockState.DockLeft)
|
---|
106 | rect.Width -= Measures.SplitterSize;
|
---|
107 | else if (DockState == DockState.DockRight)
|
---|
108 | {
|
---|
109 | rect.X += Measures.SplitterSize;
|
---|
110 | rect.Width -= Measures.SplitterSize;
|
---|
111 | }
|
---|
112 | else if (DockState == DockState.DockTop)
|
---|
113 | rect.Height -= Measures.SplitterSize;
|
---|
114 | else if (DockState == DockState.DockBottom)
|
---|
115 | {
|
---|
116 | rect.Y += Measures.SplitterSize;
|
---|
117 | rect.Height -= Measures.SplitterSize;
|
---|
118 | }
|
---|
119 |
|
---|
120 | return rect;
|
---|
121 | }
|
---|
122 | }
|
---|
123 |
|
---|
124 | protected override void OnPaint(PaintEventArgs e)
|
---|
125 | {
|
---|
126 | // if DockWindow is document, draw the border
|
---|
127 | if (DockState == DockState.Document)
|
---|
128 | e.Graphics.DrawRectangle(SystemPens.ControlDark, ClientRectangle.X, ClientRectangle.Y, ClientRectangle.Width - 1, ClientRectangle.Height - 1);
|
---|
129 |
|
---|
130 | base.OnPaint(e);
|
---|
131 | }
|
---|
132 |
|
---|
133 | protected override void OnLayout(LayoutEventArgs levent)
|
---|
134 | {
|
---|
135 | VisibleNestedPanes.Refresh();
|
---|
136 | if (VisibleNestedPanes.Count == 0)
|
---|
137 | {
|
---|
138 | if (Visible)
|
---|
139 | Visible = false;
|
---|
140 | }
|
---|
141 | else if (!Visible)
|
---|
142 | {
|
---|
143 | Visible = true;
|
---|
144 | VisibleNestedPanes.Refresh();
|
---|
145 | }
|
---|
146 |
|
---|
147 | base.OnLayout (levent);
|
---|
148 | }
|
---|
149 |
|
---|
150 | #region ISplitterDragSource Members
|
---|
151 |
|
---|
152 | void ISplitterDragSource.BeginDrag(Rectangle rectSplitter)
|
---|
153 | {
|
---|
154 | }
|
---|
155 |
|
---|
156 | void ISplitterDragSource.EndDrag()
|
---|
157 | {
|
---|
158 | }
|
---|
159 |
|
---|
160 | bool ISplitterDragSource.IsVertical
|
---|
161 | {
|
---|
162 | get { return (DockState == DockState.DockLeft || DockState == DockState.DockRight); }
|
---|
163 | }
|
---|
164 |
|
---|
165 | Rectangle ISplitterDragSource.DragLimitBounds
|
---|
166 | {
|
---|
167 | get
|
---|
168 | {
|
---|
169 | Rectangle rectLimit = DockPanel.DockArea;
|
---|
170 | Point location;
|
---|
171 | if ((Control.ModifierKeys & Keys.Shift) == 0)
|
---|
172 | location = Location;
|
---|
173 | else
|
---|
174 | location = DockPanel.DockArea.Location;
|
---|
175 |
|
---|
176 | if (((ISplitterDragSource)this).IsVertical)
|
---|
177 | {
|
---|
178 | rectLimit.X += MeasurePane.MinSize;
|
---|
179 | rectLimit.Width -= 2 * MeasurePane.MinSize;
|
---|
180 | rectLimit.Y = location.Y;
|
---|
181 | if ((Control.ModifierKeys & Keys.Shift) == 0)
|
---|
182 | rectLimit.Height = Height;
|
---|
183 | }
|
---|
184 | else
|
---|
185 | {
|
---|
186 | rectLimit.Y += MeasurePane.MinSize;
|
---|
187 | rectLimit.Height -= 2 * MeasurePane.MinSize;
|
---|
188 | rectLimit.X = location.X;
|
---|
189 | if ((Control.ModifierKeys & Keys.Shift) == 0)
|
---|
190 | rectLimit.Width = Width;
|
---|
191 | }
|
---|
192 |
|
---|
193 | return DockPanel.RectangleToScreen(rectLimit);
|
---|
194 | }
|
---|
195 | }
|
---|
196 |
|
---|
197 | void ISplitterDragSource.MoveSplitter(int offset)
|
---|
198 | {
|
---|
199 | if ((Control.ModifierKeys & Keys.Shift) != 0)
|
---|
200 | SendToBack();
|
---|
201 |
|
---|
202 | Rectangle rectDockArea = DockPanel.DockArea;
|
---|
203 | if (DockState == DockState.DockLeft && rectDockArea.Width > 0)
|
---|
204 | {
|
---|
205 | if (DockPanel.DockLeftPortion > 1)
|
---|
206 | DockPanel.DockLeftPortion = Width + offset;
|
---|
207 | else
|
---|
208 | DockPanel.DockLeftPortion += ((double)offset) / (double)rectDockArea.Width;
|
---|
209 | }
|
---|
210 | else if (DockState == DockState.DockRight && rectDockArea.Width > 0)
|
---|
211 | {
|
---|
212 | if (DockPanel.DockRightPortion > 1)
|
---|
213 | DockPanel.DockRightPortion = Width - offset;
|
---|
214 | else
|
---|
215 | DockPanel.DockRightPortion -= ((double)offset) / (double)rectDockArea.Width;
|
---|
216 | }
|
---|
217 | else if (DockState == DockState.DockBottom && rectDockArea.Height > 0)
|
---|
218 | {
|
---|
219 | if (DockPanel.DockBottomPortion > 1)
|
---|
220 | DockPanel.DockBottomPortion = Height - offset;
|
---|
221 | else
|
---|
222 | DockPanel.DockBottomPortion -= ((double)offset) / (double)rectDockArea.Height;
|
---|
223 | }
|
---|
224 | else if (DockState == DockState.DockTop && rectDockArea.Height > 0)
|
---|
225 | {
|
---|
226 | if (DockPanel.DockTopPortion > 1)
|
---|
227 | DockPanel.DockTopPortion = Height + offset;
|
---|
228 | else
|
---|
229 | DockPanel.DockTopPortion += ((double)offset) / (double)rectDockArea.Height;
|
---|
230 | }
|
---|
231 | }
|
---|
232 |
|
---|
233 | #region IDragSource Members
|
---|
234 |
|
---|
235 | Control IDragSource.DragControl
|
---|
236 | {
|
---|
237 | get { return this; }
|
---|
238 | }
|
---|
239 |
|
---|
240 | #endregion
|
---|
241 | #endregion
|
---|
242 | }
|
---|
243 | }
|
---|