Free cookie consent management tool by TermsFeed Policy Generator

source: trunk/sources/HeuristicLab.ExtLibs/HeuristicLab.WinFormsUI/2.3.1/WinFormsUI-2.3.1/Docking/DockPanel.DockDragHandler.cs @ 2645

Last change on this file since 2645 was 2645, checked in by mkommend, 14 years ago

extracted external libraries and adapted dependent plugins (ticket #837)

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