1 | using System.ComponentModel;
|
---|
2 | using System.Drawing;
|
---|
3 | using System.Drawing.Drawing2D;
|
---|
4 | using System.Windows.Forms;
|
---|
5 |
|
---|
6 | namespace WeifenLuo.WinFormsUI.Docking {
|
---|
7 | partial class DockPanel {
|
---|
8 | private sealed class DockDragHandler : DragHandler {
|
---|
9 | private class DockIndicator : DragForm {
|
---|
10 | #region IHitTest
|
---|
11 | private interface IHitTest {
|
---|
12 | DockStyle HitTest(Point pt);
|
---|
13 | DockStyle Status { get; set; }
|
---|
14 | }
|
---|
15 | #endregion
|
---|
16 |
|
---|
17 | #region PanelIndicator
|
---|
18 | private class PanelIndicator : PictureBox, IHitTest {
|
---|
19 | private static Image _imagePanelLeft = Resources.DockIndicator_PanelLeft;
|
---|
20 | private static Image _imagePanelRight = Resources.DockIndicator_PanelRight;
|
---|
21 | private static Image _imagePanelTop = Resources.DockIndicator_PanelTop;
|
---|
22 | private static Image _imagePanelBottom = Resources.DockIndicator_PanelBottom;
|
---|
23 | private static Image _imagePanelFill = Resources.DockIndicator_PanelFill;
|
---|
24 | private static Image _imagePanelLeftActive = Resources.DockIndicator_PanelLeft_Active;
|
---|
25 | private static Image _imagePanelRightActive = Resources.DockIndicator_PanelRight_Active;
|
---|
26 | private static Image _imagePanelTopActive = Resources.DockIndicator_PanelTop_Active;
|
---|
27 | private static Image _imagePanelBottomActive = Resources.DockIndicator_PanelBottom_Active;
|
---|
28 | private static Image _imagePanelFillActive = Resources.DockIndicator_PanelFill_Active;
|
---|
29 |
|
---|
30 | public PanelIndicator(DockStyle dockStyle) {
|
---|
31 | m_dockStyle = dockStyle;
|
---|
32 | SizeMode = PictureBoxSizeMode.AutoSize;
|
---|
33 | Image = ImageInactive;
|
---|
34 | }
|
---|
35 |
|
---|
36 | private DockStyle m_dockStyle;
|
---|
37 | private DockStyle DockStyle {
|
---|
38 | get { return m_dockStyle; }
|
---|
39 | }
|
---|
40 |
|
---|
41 | private DockStyle m_status;
|
---|
42 | public DockStyle Status {
|
---|
43 | get { return m_status; }
|
---|
44 | set {
|
---|
45 | if (value != DockStyle && value != DockStyle.None)
|
---|
46 | throw new InvalidEnumArgumentException();
|
---|
47 |
|
---|
48 | if (m_status == value)
|
---|
49 | return;
|
---|
50 |
|
---|
51 | m_status = value;
|
---|
52 | IsActivated = (m_status != DockStyle.None);
|
---|
53 | }
|
---|
54 | }
|
---|
55 |
|
---|
56 | private Image ImageInactive {
|
---|
57 | get {
|
---|
58 | if (DockStyle == DockStyle.Left)
|
---|
59 | return _imagePanelLeft;
|
---|
60 | else if (DockStyle == DockStyle.Right)
|
---|
61 | return _imagePanelRight;
|
---|
62 | else if (DockStyle == DockStyle.Top)
|
---|
63 | return _imagePanelTop;
|
---|
64 | else if (DockStyle == DockStyle.Bottom)
|
---|
65 | return _imagePanelBottom;
|
---|
66 | else if (DockStyle == DockStyle.Fill)
|
---|
67 | return _imagePanelFill;
|
---|
68 | else
|
---|
69 | return null;
|
---|
70 | }
|
---|
71 | }
|
---|
72 |
|
---|
73 | private Image ImageActive {
|
---|
74 | get {
|
---|
75 | if (DockStyle == DockStyle.Left)
|
---|
76 | return _imagePanelLeftActive;
|
---|
77 | else if (DockStyle == DockStyle.Right)
|
---|
78 | return _imagePanelRightActive;
|
---|
79 | else if (DockStyle == DockStyle.Top)
|
---|
80 | return _imagePanelTopActive;
|
---|
81 | else if (DockStyle == DockStyle.Bottom)
|
---|
82 | return _imagePanelBottomActive;
|
---|
83 | else if (DockStyle == DockStyle.Fill)
|
---|
84 | return _imagePanelFillActive;
|
---|
85 | else
|
---|
86 | return null;
|
---|
87 | }
|
---|
88 | }
|
---|
89 |
|
---|
90 | private bool m_isActivated = false;
|
---|
91 | private bool IsActivated {
|
---|
92 | get { return m_isActivated; }
|
---|
93 | set {
|
---|
94 | m_isActivated = value;
|
---|
95 | Image = IsActivated ? ImageActive : ImageInactive;
|
---|
96 | }
|
---|
97 | }
|
---|
98 |
|
---|
99 | public DockStyle HitTest(Point pt) {
|
---|
100 | return this.Visible && ClientRectangle.Contains(PointToClient(pt)) ? DockStyle : DockStyle.None;
|
---|
101 | }
|
---|
102 | }
|
---|
103 | #endregion PanelIndicator
|
---|
104 |
|
---|
105 | #region PaneIndicator
|
---|
106 | private class PaneIndicator : PictureBox, IHitTest {
|
---|
107 | private struct HotSpotIndex {
|
---|
108 | public HotSpotIndex(int x, int y, DockStyle dockStyle) {
|
---|
109 | m_x = x;
|
---|
110 | m_y = y;
|
---|
111 | m_dockStyle = dockStyle;
|
---|
112 | }
|
---|
113 |
|
---|
114 | private int m_x;
|
---|
115 | public int X {
|
---|
116 | get { return m_x; }
|
---|
117 | }
|
---|
118 |
|
---|
119 | private int m_y;
|
---|
120 | public int Y {
|
---|
121 | get { return m_y; }
|
---|
122 | }
|
---|
123 |
|
---|
124 | private DockStyle m_dockStyle;
|
---|
125 | public DockStyle DockStyle {
|
---|
126 | get { return m_dockStyle; }
|
---|
127 | }
|
---|
128 | }
|
---|
129 |
|
---|
130 | private static Bitmap _bitmapPaneDiamond = Resources.DockIndicator_PaneDiamond;
|
---|
131 | private static Bitmap _bitmapPaneDiamondLeft = Resources.DockIndicator_PaneDiamond_Left;
|
---|
132 | private static Bitmap _bitmapPaneDiamondRight = Resources.DockIndicator_PaneDiamond_Right;
|
---|
133 | private static Bitmap _bitmapPaneDiamondTop = Resources.DockIndicator_PaneDiamond_Top;
|
---|
134 | private static Bitmap _bitmapPaneDiamondBottom = Resources.DockIndicator_PaneDiamond_Bottom;
|
---|
135 | private static Bitmap _bitmapPaneDiamondFill = Resources.DockIndicator_PaneDiamond_Fill;
|
---|
136 | private static Bitmap _bitmapPaneDiamondHotSpot = Resources.DockIndicator_PaneDiamond_HotSpot;
|
---|
137 | private static Bitmap _bitmapPaneDiamondHotSpotIndex = Resources.DockIndicator_PaneDiamond_HotSpotIndex;
|
---|
138 | private static HotSpotIndex[] _hotSpots = new HotSpotIndex[] {
|
---|
139 | new HotSpotIndex(1, 0, DockStyle.Top),
|
---|
140 | new HotSpotIndex(0, 1, DockStyle.Left),
|
---|
141 | new HotSpotIndex(1, 1, DockStyle.Fill),
|
---|
142 | new HotSpotIndex(2, 1, DockStyle.Right),
|
---|
143 | new HotSpotIndex(1, 2, DockStyle.Bottom)
|
---|
144 | };
|
---|
145 | private static GraphicsPath _displayingGraphicsPath = DrawHelper.CalculateGraphicsPathFromBitmap(_bitmapPaneDiamond);
|
---|
146 |
|
---|
147 | public PaneIndicator() {
|
---|
148 | SizeMode = PictureBoxSizeMode.AutoSize;
|
---|
149 | Image = _bitmapPaneDiamond;
|
---|
150 | Region = new Region(DisplayingGraphicsPath);
|
---|
151 | }
|
---|
152 |
|
---|
153 | public static GraphicsPath DisplayingGraphicsPath {
|
---|
154 | get { return _displayingGraphicsPath; }
|
---|
155 | }
|
---|
156 |
|
---|
157 | public DockStyle HitTest(Point pt) {
|
---|
158 | if (!Visible)
|
---|
159 | return DockStyle.None;
|
---|
160 |
|
---|
161 | pt = PointToClient(pt);
|
---|
162 | if (!ClientRectangle.Contains(pt))
|
---|
163 | return DockStyle.None;
|
---|
164 |
|
---|
165 | for (int i = _hotSpots.GetLowerBound(0); i <= _hotSpots.GetUpperBound(0); i++) {
|
---|
166 | if (_bitmapPaneDiamondHotSpot.GetPixel(pt.X, pt.Y) == _bitmapPaneDiamondHotSpotIndex.GetPixel(_hotSpots[i].X, _hotSpots[i].Y))
|
---|
167 | return _hotSpots[i].DockStyle;
|
---|
168 | }
|
---|
169 |
|
---|
170 | return DockStyle.None;
|
---|
171 | }
|
---|
172 |
|
---|
173 | private DockStyle m_status = DockStyle.None;
|
---|
174 | public DockStyle Status {
|
---|
175 | get { return m_status; }
|
---|
176 | set {
|
---|
177 | m_status = value;
|
---|
178 | if (m_status == DockStyle.None)
|
---|
179 | Image = _bitmapPaneDiamond;
|
---|
180 | else if (m_status == DockStyle.Left)
|
---|
181 | Image = _bitmapPaneDiamondLeft;
|
---|
182 | else if (m_status == DockStyle.Right)
|
---|
183 | Image = _bitmapPaneDiamondRight;
|
---|
184 | else if (m_status == DockStyle.Top)
|
---|
185 | Image = _bitmapPaneDiamondTop;
|
---|
186 | else if (m_status == DockStyle.Bottom)
|
---|
187 | Image = _bitmapPaneDiamondBottom;
|
---|
188 | else if (m_status == DockStyle.Fill)
|
---|
189 | Image = _bitmapPaneDiamondFill;
|
---|
190 | }
|
---|
191 | }
|
---|
192 | }
|
---|
193 | #endregion PaneIndicator
|
---|
194 |
|
---|
195 | #region consts
|
---|
196 | private int _PanelIndicatorMargin = 10;
|
---|
197 | #endregion
|
---|
198 |
|
---|
199 | private DockDragHandler m_dragHandler;
|
---|
200 |
|
---|
201 | public DockIndicator(DockDragHandler dragHandler) {
|
---|
202 | m_dragHandler = dragHandler;
|
---|
203 | Controls.AddRange(new Control[] {
|
---|
204 | PaneDiamond,
|
---|
205 | PanelLeft,
|
---|
206 | PanelRight,
|
---|
207 | PanelTop,
|
---|
208 | PanelBottom,
|
---|
209 | PanelFill
|
---|
210 | });
|
---|
211 | Region = new Region(Rectangle.Empty);
|
---|
212 | }
|
---|
213 |
|
---|
214 | private PaneIndicator m_paneDiamond = null;
|
---|
215 | private PaneIndicator PaneDiamond {
|
---|
216 | get {
|
---|
217 | if (m_paneDiamond == null)
|
---|
218 | m_paneDiamond = new PaneIndicator();
|
---|
219 |
|
---|
220 | return m_paneDiamond;
|
---|
221 | }
|
---|
222 | }
|
---|
223 |
|
---|
224 | private PanelIndicator m_panelLeft = null;
|
---|
225 | private PanelIndicator PanelLeft {
|
---|
226 | get {
|
---|
227 | if (m_panelLeft == null)
|
---|
228 | m_panelLeft = new PanelIndicator(DockStyle.Left);
|
---|
229 |
|
---|
230 | return m_panelLeft;
|
---|
231 | }
|
---|
232 | }
|
---|
233 |
|
---|
234 | private PanelIndicator m_panelRight = null;
|
---|
235 | private PanelIndicator PanelRight {
|
---|
236 | get {
|
---|
237 | if (m_panelRight == null)
|
---|
238 | m_panelRight = new PanelIndicator(DockStyle.Right);
|
---|
239 |
|
---|
240 | return m_panelRight;
|
---|
241 | }
|
---|
242 | }
|
---|
243 |
|
---|
244 | private PanelIndicator m_panelTop = null;
|
---|
245 | private PanelIndicator PanelTop {
|
---|
246 | get {
|
---|
247 | if (m_panelTop == null)
|
---|
248 | m_panelTop = new PanelIndicator(DockStyle.Top);
|
---|
249 |
|
---|
250 | return m_panelTop;
|
---|
251 | }
|
---|
252 | }
|
---|
253 |
|
---|
254 | private PanelIndicator m_panelBottom = null;
|
---|
255 | private PanelIndicator PanelBottom {
|
---|
256 | get {
|
---|
257 | if (m_panelBottom == null)
|
---|
258 | m_panelBottom = new PanelIndicator(DockStyle.Bottom);
|
---|
259 |
|
---|
260 | return m_panelBottom;
|
---|
261 | }
|
---|
262 | }
|
---|
263 |
|
---|
264 | private PanelIndicator m_panelFill = null;
|
---|
265 | private PanelIndicator PanelFill {
|
---|
266 | get {
|
---|
267 | if (m_panelFill == null)
|
---|
268 | m_panelFill = new PanelIndicator(DockStyle.Fill);
|
---|
269 |
|
---|
270 | return m_panelFill;
|
---|
271 | }
|
---|
272 | }
|
---|
273 |
|
---|
274 | private bool m_fullPanelEdge = false;
|
---|
275 | public bool FullPanelEdge {
|
---|
276 | get { return m_fullPanelEdge; }
|
---|
277 | set {
|
---|
278 | if (m_fullPanelEdge == value)
|
---|
279 | return;
|
---|
280 |
|
---|
281 | m_fullPanelEdge = value;
|
---|
282 | RefreshChanges();
|
---|
283 | }
|
---|
284 | }
|
---|
285 |
|
---|
286 | public DockDragHandler DragHandler {
|
---|
287 | get { return m_dragHandler; }
|
---|
288 | }
|
---|
289 |
|
---|
290 | public DockPanel DockPanel {
|
---|
291 | get { return DragHandler.DockPanel; }
|
---|
292 | }
|
---|
293 |
|
---|
294 | private DockPane m_dockPane = null;
|
---|
295 | public DockPane DockPane {
|
---|
296 | get { return m_dockPane; }
|
---|
297 | internal set {
|
---|
298 | if (m_dockPane == value)
|
---|
299 | return;
|
---|
300 |
|
---|
301 | DockPane oldDisplayingPane = DisplayingPane;
|
---|
302 | m_dockPane = value;
|
---|
303 | if (oldDisplayingPane != DisplayingPane)
|
---|
304 | RefreshChanges();
|
---|
305 | }
|
---|
306 | }
|
---|
307 |
|
---|
308 | private IHitTest m_hitTest = null;
|
---|
309 | private IHitTest HitTestResult {
|
---|
310 | get { return m_hitTest; }
|
---|
311 | set {
|
---|
312 | if (m_hitTest == value)
|
---|
313 | return;
|
---|
314 |
|
---|
315 | if (m_hitTest != null)
|
---|
316 | m_hitTest.Status = DockStyle.None;
|
---|
317 |
|
---|
318 | m_hitTest = value;
|
---|
319 | }
|
---|
320 | }
|
---|
321 |
|
---|
322 | private DockPane DisplayingPane {
|
---|
323 | get { return ShouldPaneDiamondVisible() ? DockPane : null; }
|
---|
324 | }
|
---|
325 |
|
---|
326 | private void RefreshChanges() {
|
---|
327 | Region region = new Region(Rectangle.Empty);
|
---|
328 | Rectangle rectDockArea = FullPanelEdge ? DockPanel.DockArea : DockPanel.DocumentWindowBounds;
|
---|
329 |
|
---|
330 | rectDockArea = RectangleToClient(DockPanel.RectangleToScreen(rectDockArea));
|
---|
331 | if (ShouldPanelIndicatorVisible(DockState.DockLeft)) {
|
---|
332 | PanelLeft.Location = new Point(rectDockArea.X + _PanelIndicatorMargin, rectDockArea.Y + (rectDockArea.Height - PanelRight.Height) / 2);
|
---|
333 | PanelLeft.Visible = true;
|
---|
334 | region.Union(PanelLeft.Bounds);
|
---|
335 | } else
|
---|
336 | PanelLeft.Visible = false;
|
---|
337 |
|
---|
338 | if (ShouldPanelIndicatorVisible(DockState.DockRight)) {
|
---|
339 | PanelRight.Location = new Point(rectDockArea.X + rectDockArea.Width - PanelRight.Width - _PanelIndicatorMargin, rectDockArea.Y + (rectDockArea.Height - PanelRight.Height) / 2);
|
---|
340 | PanelRight.Visible = true;
|
---|
341 | region.Union(PanelRight.Bounds);
|
---|
342 | } else
|
---|
343 | PanelRight.Visible = false;
|
---|
344 |
|
---|
345 | if (ShouldPanelIndicatorVisible(DockState.DockTop)) {
|
---|
346 | PanelTop.Location = new Point(rectDockArea.X + (rectDockArea.Width - PanelTop.Width) / 2, rectDockArea.Y + _PanelIndicatorMargin);
|
---|
347 | PanelTop.Visible = true;
|
---|
348 | region.Union(PanelTop.Bounds);
|
---|
349 | } else
|
---|
350 | PanelTop.Visible = false;
|
---|
351 |
|
---|
352 | if (ShouldPanelIndicatorVisible(DockState.DockBottom)) {
|
---|
353 | PanelBottom.Location = new Point(rectDockArea.X + (rectDockArea.Width - PanelBottom.Width) / 2, rectDockArea.Y + rectDockArea.Height - PanelBottom.Height - _PanelIndicatorMargin);
|
---|
354 | PanelBottom.Visible = true;
|
---|
355 | region.Union(PanelBottom.Bounds);
|
---|
356 | } else
|
---|
357 | PanelBottom.Visible = false;
|
---|
358 |
|
---|
359 | if (ShouldPanelIndicatorVisible(DockState.Document)) {
|
---|
360 | Rectangle rectDocumentWindow = RectangleToClient(DockPanel.RectangleToScreen(DockPanel.DocumentWindowBounds));
|
---|
361 | PanelFill.Location = new Point(rectDocumentWindow.X + (rectDocumentWindow.Width - PanelFill.Width) / 2, rectDocumentWindow.Y + (rectDocumentWindow.Height - PanelFill.Height) / 2);
|
---|
362 | PanelFill.Visible = true;
|
---|
363 | region.Union(PanelFill.Bounds);
|
---|
364 | } else
|
---|
365 | PanelFill.Visible = false;
|
---|
366 |
|
---|
367 | if (ShouldPaneDiamondVisible()) {
|
---|
368 | Rectangle rect = RectangleToClient(DockPane.RectangleToScreen(DockPane.ClientRectangle));
|
---|
369 | PaneDiamond.Location = new Point(rect.Left + (rect.Width - PaneDiamond.Width) / 2, rect.Top + (rect.Height - PaneDiamond.Height) / 2);
|
---|
370 | PaneDiamond.Visible = true;
|
---|
371 | using (GraphicsPath graphicsPath = PaneIndicator.DisplayingGraphicsPath.Clone() as GraphicsPath) {
|
---|
372 | Point[] pts = new Point[]
|
---|
373 | {
|
---|
374 | new Point(PaneDiamond.Left, PaneDiamond.Top),
|
---|
375 | new Point(PaneDiamond.Right, PaneDiamond.Top),
|
---|
376 | new Point(PaneDiamond.Left, PaneDiamond.Bottom)
|
---|
377 | };
|
---|
378 | using (Matrix matrix = new Matrix(PaneDiamond.ClientRectangle, pts)) {
|
---|
379 | graphicsPath.Transform(matrix);
|
---|
380 | }
|
---|
381 | region.Union(graphicsPath);
|
---|
382 | }
|
---|
383 | } else
|
---|
384 | PaneDiamond.Visible = false;
|
---|
385 |
|
---|
386 | Region = region;
|
---|
387 | }
|
---|
388 |
|
---|
389 | private bool ShouldPanelIndicatorVisible(DockState dockState) {
|
---|
390 | if (!Visible)
|
---|
391 | return false;
|
---|
392 |
|
---|
393 | if (DockPanel.DockWindows[dockState].Visible)
|
---|
394 | return false;
|
---|
395 |
|
---|
396 | return DragHandler.DragSource.IsDockStateValid(dockState);
|
---|
397 | }
|
---|
398 |
|
---|
399 | private bool ShouldPaneDiamondVisible() {
|
---|
400 | if (DockPane == null)
|
---|
401 | return false;
|
---|
402 |
|
---|
403 | if (!DockPanel.AllowEndUserNestedDocking)
|
---|
404 | return false;
|
---|
405 |
|
---|
406 | return DragHandler.DragSource.CanDockTo(DockPane);
|
---|
407 | }
|
---|
408 |
|
---|
409 | public override void Show(bool bActivate) {
|
---|
410 | base.Show(bActivate);
|
---|
411 | Bounds = SystemInformation.VirtualScreen;
|
---|
412 | RefreshChanges();
|
---|
413 | }
|
---|
414 |
|
---|
415 | public void TestDrop() {
|
---|
416 | Point pt = Control.MousePosition;
|
---|
417 | DockPane = DockHelper.PaneAtPoint(pt, DockPanel);
|
---|
418 |
|
---|
419 | if (TestDrop(PanelLeft, pt) != DockStyle.None)
|
---|
420 | HitTestResult = PanelLeft;
|
---|
421 | else if (TestDrop(PanelRight, pt) != DockStyle.None)
|
---|
422 | HitTestResult = PanelRight;
|
---|
423 | else if (TestDrop(PanelTop, pt) != DockStyle.None)
|
---|
424 | HitTestResult = PanelTop;
|
---|
425 | else if (TestDrop(PanelBottom, pt) != DockStyle.None)
|
---|
426 | HitTestResult = PanelBottom;
|
---|
427 | else if (TestDrop(PanelFill, pt) != DockStyle.None)
|
---|
428 | HitTestResult = PanelFill;
|
---|
429 | else if (TestDrop(PaneDiamond, pt) != DockStyle.None)
|
---|
430 | HitTestResult = PaneDiamond;
|
---|
431 | else
|
---|
432 | HitTestResult = null;
|
---|
433 |
|
---|
434 | if (HitTestResult != null) {
|
---|
435 | if (HitTestResult is PaneIndicator)
|
---|
436 | DragHandler.Outline.Show(DockPane, HitTestResult.Status);
|
---|
437 | else
|
---|
438 | DragHandler.Outline.Show(DockPanel, HitTestResult.Status, FullPanelEdge);
|
---|
439 | }
|
---|
440 | }
|
---|
441 |
|
---|
442 | private static DockStyle TestDrop(IHitTest hitTest, Point pt) {
|
---|
443 | return hitTest.Status = hitTest.HitTest(pt);
|
---|
444 | }
|
---|
445 | }
|
---|
446 |
|
---|
447 | private class DockOutline : DockOutlineBase {
|
---|
448 | public DockOutline() {
|
---|
449 | m_dragForm = new DragForm();
|
---|
450 | SetDragForm(Rectangle.Empty);
|
---|
451 | DragForm.BackColor = SystemColors.ActiveCaption;
|
---|
452 | DragForm.Opacity = 0.5;
|
---|
453 | DragForm.Show(false);
|
---|
454 | }
|
---|
455 |
|
---|
456 | DragForm m_dragForm;
|
---|
457 | private DragForm DragForm {
|
---|
458 | get { return m_dragForm; }
|
---|
459 | }
|
---|
460 |
|
---|
461 | protected override void OnShow() {
|
---|
462 | CalculateRegion();
|
---|
463 | }
|
---|
464 |
|
---|
465 | protected override void OnClose() {
|
---|
466 | DragForm.Close();
|
---|
467 | }
|
---|
468 |
|
---|
469 | private void CalculateRegion() {
|
---|
470 | if (SameAsOldValue)
|
---|
471 | return;
|
---|
472 |
|
---|
473 | if (!FloatWindowBounds.IsEmpty)
|
---|
474 | SetOutline(FloatWindowBounds);
|
---|
475 | else if (DockTo is DockPanel)
|
---|
476 | SetOutline(DockTo as DockPanel, Dock, (ContentIndex != 0));
|
---|
477 | else if (DockTo is DockPane)
|
---|
478 | SetOutline(DockTo as DockPane, Dock, ContentIndex);
|
---|
479 | else
|
---|
480 | SetOutline();
|
---|
481 | }
|
---|
482 |
|
---|
483 | private void SetOutline() {
|
---|
484 | SetDragForm(Rectangle.Empty);
|
---|
485 | }
|
---|
486 |
|
---|
487 | private void SetOutline(Rectangle floatWindowBounds) {
|
---|
488 | SetDragForm(floatWindowBounds);
|
---|
489 | }
|
---|
490 |
|
---|
491 | private void SetOutline(DockPanel dockPanel, DockStyle dock, bool fullPanelEdge) {
|
---|
492 | Rectangle rect = fullPanelEdge ? dockPanel.DockArea : dockPanel.DocumentWindowBounds;
|
---|
493 | rect.Location = dockPanel.PointToScreen(rect.Location);
|
---|
494 | if (dock == DockStyle.Top) {
|
---|
495 | int height = dockPanel.GetDockWindowSize(DockState.DockTop);
|
---|
496 | rect = new Rectangle(rect.X, rect.Y, rect.Width, height);
|
---|
497 | } else if (dock == DockStyle.Bottom) {
|
---|
498 | int height = dockPanel.GetDockWindowSize(DockState.DockBottom);
|
---|
499 | rect = new Rectangle(rect.X, rect.Bottom - height, rect.Width, height);
|
---|
500 | } else if (dock == DockStyle.Left) {
|
---|
501 | int width = dockPanel.GetDockWindowSize(DockState.DockLeft);
|
---|
502 | rect = new Rectangle(rect.X, rect.Y, width, rect.Height);
|
---|
503 | } else if (dock == DockStyle.Right) {
|
---|
504 | int width = dockPanel.GetDockWindowSize(DockState.DockRight);
|
---|
505 | rect = new Rectangle(rect.Right - width, rect.Y, width, rect.Height);
|
---|
506 | } else if (dock == DockStyle.Fill) {
|
---|
507 | rect = dockPanel.DocumentWindowBounds;
|
---|
508 | rect.Location = dockPanel.PointToScreen(rect.Location);
|
---|
509 | }
|
---|
510 |
|
---|
511 | SetDragForm(rect);
|
---|
512 | }
|
---|
513 |
|
---|
514 | private void SetOutline(DockPane pane, DockStyle dock, int contentIndex) {
|
---|
515 | if (dock != DockStyle.Fill) {
|
---|
516 | Rectangle rect = pane.DisplayingRectangle;
|
---|
517 | if (dock == DockStyle.Right)
|
---|
518 | rect.X += rect.Width / 2;
|
---|
519 | if (dock == DockStyle.Bottom)
|
---|
520 | rect.Y += rect.Height / 2;
|
---|
521 | if (dock == DockStyle.Left || dock == DockStyle.Right)
|
---|
522 | rect.Width -= rect.Width / 2;
|
---|
523 | if (dock == DockStyle.Top || dock == DockStyle.Bottom)
|
---|
524 | rect.Height -= rect.Height / 2;
|
---|
525 | rect.Location = pane.PointToScreen(rect.Location);
|
---|
526 |
|
---|
527 | SetDragForm(rect);
|
---|
528 | } else if (contentIndex == -1) {
|
---|
529 | Rectangle rect = pane.DisplayingRectangle;
|
---|
530 | rect.Location = pane.PointToScreen(rect.Location);
|
---|
531 | SetDragForm(rect);
|
---|
532 | } else {
|
---|
533 | using (GraphicsPath path = pane.TabStripControl.GetOutline(contentIndex)) {
|
---|
534 | RectangleF rectF = path.GetBounds();
|
---|
535 | Rectangle rect = new Rectangle((int)rectF.X, (int)rectF.Y, (int)rectF.Width, (int)rectF.Height);
|
---|
536 | using (Matrix matrix = new Matrix(rect, new Point[] { new Point(0, 0), new Point(rect.Width, 0), new Point(0, rect.Height) })) {
|
---|
537 | path.Transform(matrix);
|
---|
538 | }
|
---|
539 | Region region = new Region(path);
|
---|
540 | SetDragForm(rect, region);
|
---|
541 | }
|
---|
542 | }
|
---|
543 | }
|
---|
544 |
|
---|
545 | private void SetDragForm(Rectangle rect) {
|
---|
546 | DragForm.Bounds = rect;
|
---|
547 | if (rect == Rectangle.Empty)
|
---|
548 | DragForm.Region = new Region(Rectangle.Empty);
|
---|
549 | else if (DragForm.Region != null)
|
---|
550 | DragForm.Region = null;
|
---|
551 | }
|
---|
552 |
|
---|
553 | private void SetDragForm(Rectangle rect, Region region) {
|
---|
554 | DragForm.Bounds = rect;
|
---|
555 | DragForm.Region = region;
|
---|
556 | }
|
---|
557 | }
|
---|
558 |
|
---|
559 | public DockDragHandler(DockPanel panel)
|
---|
560 | : base(panel) {
|
---|
561 | }
|
---|
562 |
|
---|
563 | public new IDockDragSource DragSource {
|
---|
564 | get { return base.DragSource as IDockDragSource; }
|
---|
565 | set { base.DragSource = value; }
|
---|
566 | }
|
---|
567 |
|
---|
568 | private DockOutlineBase m_outline;
|
---|
569 | public DockOutlineBase Outline {
|
---|
570 | get { return m_outline; }
|
---|
571 | private set { m_outline = value; }
|
---|
572 | }
|
---|
573 |
|
---|
574 | private DockIndicator m_indicator;
|
---|
575 | private DockIndicator Indicator {
|
---|
576 | get { return m_indicator; }
|
---|
577 | set { m_indicator = value; }
|
---|
578 | }
|
---|
579 |
|
---|
580 | private Rectangle m_floatOutlineBounds;
|
---|
581 | private Rectangle FloatOutlineBounds {
|
---|
582 | get { return m_floatOutlineBounds; }
|
---|
583 | set { m_floatOutlineBounds = value; }
|
---|
584 | }
|
---|
585 |
|
---|
586 | public void BeginDrag(IDockDragSource dragSource) {
|
---|
587 | DragSource = dragSource;
|
---|
588 |
|
---|
589 | if (!BeginDrag()) {
|
---|
590 | DragSource = null;
|
---|
591 | return;
|
---|
592 | }
|
---|
593 |
|
---|
594 | Outline = new DockOutline();
|
---|
595 | Indicator = new DockIndicator(this);
|
---|
596 | Indicator.Show(false);
|
---|
597 |
|
---|
598 | FloatOutlineBounds = DragSource.BeginDrag(StartMousePosition);
|
---|
599 | }
|
---|
600 |
|
---|
601 | protected override void OnDragging() {
|
---|
602 | TestDrop();
|
---|
603 | }
|
---|
604 |
|
---|
605 | protected override void OnEndDrag(bool abort) {
|
---|
606 | DockPanel.SuspendLayout(true);
|
---|
607 |
|
---|
608 | Outline.Close();
|
---|
609 | Indicator.Close();
|
---|
610 |
|
---|
611 | EndDrag(abort);
|
---|
612 |
|
---|
613 | // Queue a request to layout all children controls
|
---|
614 | DockPanel.PerformMdiClientLayout();
|
---|
615 |
|
---|
616 | DockPanel.ResumeLayout(true, true);
|
---|
617 |
|
---|
618 | DragSource = null;
|
---|
619 | }
|
---|
620 |
|
---|
621 | private void TestDrop() {
|
---|
622 | Outline.FlagTestDrop = false;
|
---|
623 |
|
---|
624 | Indicator.FullPanelEdge = ((Control.ModifierKeys & Keys.Shift) != 0);
|
---|
625 |
|
---|
626 | if ((Control.ModifierKeys & Keys.Control) == 0) {
|
---|
627 | Indicator.TestDrop();
|
---|
628 |
|
---|
629 | if (!Outline.FlagTestDrop) {
|
---|
630 | DockPane pane = DockHelper.PaneAtPoint(Control.MousePosition, DockPanel);
|
---|
631 | if (pane != null && DragSource.IsDockStateValid(pane.DockState))
|
---|
632 | pane.TestDrop(DragSource, Outline);
|
---|
633 | }
|
---|
634 |
|
---|
635 | if (!Outline.FlagTestDrop && DragSource.IsDockStateValid(DockState.Float)) {
|
---|
636 | FloatWindow floatWindow = DockHelper.FloatWindowAtPoint(Control.MousePosition, DockPanel);
|
---|
637 | if (floatWindow != null)
|
---|
638 | floatWindow.TestDrop(DragSource, Outline);
|
---|
639 | }
|
---|
640 | } else
|
---|
641 | Indicator.DockPane = DockHelper.PaneAtPoint(Control.MousePosition, DockPanel);
|
---|
642 |
|
---|
643 | if (!Outline.FlagTestDrop) {
|
---|
644 | if (DragSource.IsDockStateValid(DockState.Float)) {
|
---|
645 | Rectangle rect = FloatOutlineBounds;
|
---|
646 | rect.Offset(Control.MousePosition.X - StartMousePosition.X, Control.MousePosition.Y - StartMousePosition.Y);
|
---|
647 | Outline.Show(rect);
|
---|
648 | }
|
---|
649 | }
|
---|
650 |
|
---|
651 | if (!Outline.FlagTestDrop) {
|
---|
652 | Cursor.Current = Cursors.No;
|
---|
653 | Outline.Show();
|
---|
654 | } else
|
---|
655 | Cursor.Current = DragControl.Cursor;
|
---|
656 | }
|
---|
657 |
|
---|
658 | private void EndDrag(bool abort) {
|
---|
659 | if (abort)
|
---|
660 | return;
|
---|
661 |
|
---|
662 | if (!Outline.FloatWindowBounds.IsEmpty)
|
---|
663 | DragSource.FloatAt(Outline.FloatWindowBounds);
|
---|
664 | else if (Outline.DockTo is DockPane) {
|
---|
665 | DockPane pane = Outline.DockTo as DockPane;
|
---|
666 | DragSource.DockTo(pane, Outline.Dock, Outline.ContentIndex);
|
---|
667 | } else if (Outline.DockTo is DockPanel) {
|
---|
668 | DockPanel panel = Outline.DockTo as DockPanel;
|
---|
669 | panel.UpdateDockWindowZOrder(Outline.Dock, Outline.FlagFullEdge);
|
---|
670 | DragSource.DockTo(panel, Outline.Dock);
|
---|
671 | }
|
---|
672 | }
|
---|
673 | }
|
---|
674 |
|
---|
675 | private DockDragHandler m_dockDragHandler = null;
|
---|
676 | private DockDragHandler GetDockDragHandler() {
|
---|
677 | if (m_dockDragHandler == null)
|
---|
678 | m_dockDragHandler = new DockDragHandler(this);
|
---|
679 | return m_dockDragHandler;
|
---|
680 | }
|
---|
681 |
|
---|
682 | internal void BeginDrag(IDockDragSource dragSource) {
|
---|
683 | GetDockDragHandler().BeginDrag(dragSource);
|
---|
684 | }
|
---|
685 | }
|
---|
686 | }
|
---|